static void addStudent() { Console.Clear(); Console.Write("Please enter name: "); String name = Console.ReadLine(); Console.Write("Please enter ID: "); String id = Console.ReadLine(); Console.Write("Please enter gender: "); String gender = Console.ReadLine(); Student s = new Student(name, id, gender); foreach (string str in gradebooks) { s.addGrade(new Grade(str)); } students.Add(s); }
public static List<Student> readFromFile() { List<Student> students = new List<Student>(); try { using (StreamReader sr = new StreamReader("Gradebook.txt")) { int nStudents = Int32.Parse(sr.ReadLine()); int nCourses = Int32.Parse(sr.ReadLine()); List<string> courses = new List<string>(); for (int i = 0; i < nCourses; i++) { courses.Add(sr.ReadLine()); } for (int i = 0; i < nStudents; i++) { Student s = new Student(sr.ReadLine(), sr.ReadLine(), sr.ReadLine()); foreach (string course in courses) { Grade g = new Grade(course); g.ExerciseScore = Double.Parse(sr.ReadLine()); g.ExamScore = Double.Parse(sr.ReadLine()); g.FinalsScore = Double.Parse(sr.ReadLine()); g.FinalGrade = Double.Parse(sr.ReadLine()); s.addGrade(g); } students.Add(s); } } } catch (Exception e) { Console.WriteLine("The file could not be read:"); Console.WriteLine(e.Message); } return students; }