static void Main(string[] args) { Logger.Log("Tracker started", priority: 0); //this is called a names argument and saves having //to provide the second argument (which is set to default) Payroll payroll = new Payroll(); payroll.PayAll(); var adding = true; while (adding) { try { Logger.Log("Adding new Student"); var newStudent = new Student(); newStudent.Name = Util.Console.Ask("Student Name: "); newStudent.Grade = (Util.Console.AskInt("Student Grade: ")); newStudent.School = (School)Util.Console.AskInt("Student SchoolName: " + "(type the corresponding number):\n " + "0: Hogwarts High \n " + "1: Harvard \n " + "2: MIT \n "); newStudent.Birthday = Util.Console.Ask("Student Birthday: "); newStudent.Address = Util.Console.Ask("Student Address: "); newStudent.Phone = (Util.Console.AskInt("Student Phone Number: ")); students.Add(newStudent); Student.Count++; Console.WriteLine("Student Count: {0}", Student.Count); Console.WriteLine("Add another? y/n"); if (Console.ReadLine() != "y") { adding = false; } } catch (FormatException msg) { Console.WriteLine(msg.Message); //much more specific - needs to be first //.Message will clean up the error } catch (Exception) { Console.WriteLine("Error - please try again"); } } ShowGrade(" Peter "); //here we pass in the name for the search function foreach (var student in students) { Console.WriteLine("Name: {0}, Grade: {1}", student.Name, student.Grade); Exports(); } }
//This method performs most of the actions a user can make. static void schoolTracker() { students.Add(new Student { Name = "John", Grade = 89, Birthday = "Oct 8", Adress = "Tverrveien", Phone = 123587, School = (School)0 }); students.Add(new Student { Name = "Rebecca", Grade = 46, Birthday = "jan 8", Adress = "Tverrveien", Phone = 1644983, School = (School)2 }); students.Add(new Student { Name = "Arthur", Grade = 79, Birthday = "Nov 8", Adress = "Tverrveien", Phone = 46587133, School = (School)3 }); teachers.Add(new Teacher { Name = "Anderson", Adress = "London", Phone = 93623487, Faculty = "Sciences", Major = "Physics", Salary = 2300, School = (School)2 }); teachers.Add(new Teacher { Name = "Jackson", Adress = "New York", Phone = 23413523, Faculty = "Arts", Major = "Music", Salary = 2200, School = (School)2 }); principals.Add(new Principal { Name = "Dumbledore", Adress = "Secret", Phone = 23155132, Salary = 4500, School = (School)0 }); bool b = false; while (!b) { Console.WriteLine("This is the student tracker. Would you like to:\n"); Console.WriteLine("a) Register a new student with corresponding grades?"); Console.WriteLine("b) Display a particular student with corresponding grades?"); Console.WriteLine("c) Display all current students with corresponding grades?"); Console.WriteLine("d) Hire staff?"); Console.WriteLine("e) Issue monthly pay?"); Console.WriteLine("e) Exit\n"); var input = Console.ReadLine(); switch (input) { case "a": try { var newStudent = new Student(); newStudent.Name = Util.Console.Ask("Student name: "); newStudent.Grade = Util.Console.AskInt("Student grade: "); newStudent.Birthday = Util.Console.Ask("Student birthday: "); newStudent.Phone = Util.Console.AskInt("Student phone: "); newStudent.Adress = Util.Console.Ask("Student adress: "); newStudent.School = (School)Util.Console.AskInt("Student school: \nType the corresponding number: \n 0: Hogwarts \n 1: UiA \n 2: Oxford \n 3: UCLA\n) "); students.Add(newStudent); } catch (FormatException msg) { Console.WriteLine(msg.Message); } catch (Exception) { Console.WriteLine("Error adding student, please try again"); } break; case "b": var findStudent = Console.ReadLine(); var item = students.Where(o => o.Name == findStudent); if (item != null) { foreach (var student in students.Where(o => o.Name == findStudent)) { Console.WriteLine("Student information:\n"); Console.WriteLine("Student name:" + student.Name); Console.WriteLine("Student grade:" + student.Grade); Console.WriteLine("Student birthday:" + student.Birthday); Console.WriteLine("Student information:" + student.Phone); Console.WriteLine("Student adress:" + student.Adress); Console.WriteLine("Student school:" + student.School + "\n"); } } else { Console.WriteLine("Student not found"); } break; case "c": foreach (var student in students) { Console.WriteLine("Student {0} has the grade {1}", student.Name, student.Grade); } break; case "d": HireStaff(); break; case "e": Payroll systemPayroll = new Payroll(); systemPayroll.PayAll(); break; default: b = true; break; } } }