Exercise Develop an application that maintains a list of Course objects. The cla
ID: 3918897 • Letter: E
Question
Exercise Develop an application that maintains a list of Course objects. The class Course has a course number like "IC201" and a list of Student objects. The class Student has id number and letter grade like "A+". Your menu has the following commands 1. List the courses and the number of students sorted by course number 2. List students and their grades in a course (take the course number from user) 3. List courses taken by a student (take the id number from user) Use the following data to test your application ICS201 201511110 A 201522220 B+ 201512120 D+ ICS102 201533330 C 201522220 A 201512220 D+ MATH102 201511110 A+ 201512120 D+Explanation / Answer
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WriteTextFile
{
public class Student
{
public int StudentId { get; set; }
public string Grade { get; set; }
public string CourseId { get; set; }
}
public class Course
{
public string CourseNo { get; set; }
}
class Program
{
static void Main(string[] args)
{
List<Student> StudentList = new List<Student>(){
new Student(){StudentId=201511110,Grade="A",CourseId="ICS201"},
new Student(){StudentId=201522220,Grade="B+",CourseId="ICS201"},
new Student(){StudentId=201512120,Grade="D+",CourseId="ICS201"},
new Student(){StudentId=201533330,Grade="C",CourseId="ICS102"},
new Student(){StudentId=201522220,Grade="A",CourseId="ICS102"},
new Student(){StudentId=201512220,Grade="A+",CourseId="ICS102"},
new Student(){StudentId=201511110,Grade="A+",CourseId="MATH102"},
new Student(){StudentId=201512120,Grade="D+",CourseId="MATH102"}
};
List<Course> CourseList = new List<Course>() {
new Course(){CourseNo="ICS201"},
new Course(){CourseNo="ICS102"},
new Course(){CourseNo="MATH102"}
};
// list of courses and the number of students sorted by course number
Console.WriteLine("list of courses and the number of students sorted by course number ---------------------------------------------------");
foreach (var item in StudentList.OrderBy(m => m.CourseId).ToList())
{
Console.WriteLine("Student Id:" + item.StudentId + " ,Grade :" + item.Grade + " , Cource Id :" + item.CourseId);
}
Console.WriteLine("--------------------------------------------------- OR ------------------------------------------");
foreach (var course in CourseList.OrderBy(c => c.CourseNo))
{
foreach (var item in StudentList.Where(s => s.CourseId == course.CourseNo))
{
Console.WriteLine("Student Id:" + item.StudentId + " ,Grade :" + item.Grade + " , Cource Id :" + item.CourseId);
}
}
// list the student and their grades in a course(taken from user )
Console.WriteLine("------------------------------------ list the student and their grades in a course(taken course number from user ) -------------------------------------");
CourseDetails:
Console.Write("Enter Course No. :");
string CourseId = Console.ReadLine();
List<Student> StudentDetails = StudentList.Where(s => s.CourseId == CourseId).ToList();
if (StudentDetails != null)
{
foreach (var item in StudentDetails)
{
Console.WriteLine("Student Id:" + item.StudentId + " ,Grade :" + item.Grade );
}
}
else
{
Console.WriteLine("Student Details is not found.");
goto CourseDetails;
}
Console.WriteLine("------------------------------------ list the course taken by a student (taken student id from user ) -------------------------------------");
StudentDetails:
Console.Write("Enter Course No. :");
int StudentId =Convert.ToInt32(Console.ReadLine());
List<string> CourseDetails = StudentList.Where(s => s.StudentId == StudentId).Select(s=>s.CourseId).ToList();
if (StudentDetails != null)
{
foreach (var item in StudentDetails.Distinct())
{
Console.WriteLine("Course Id:"+item.CourseId);
}
}
else
{
Console.WriteLine("Course Details is not found.");
goto StudentDetails;
}
Console.WriteLine("------------------------------------ THANK YOU ");
Console.ReadKey();
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.