private void AddStudent() { Console.WriteLine("Enter Id"); string userInput = Console.ReadLine(); int id; if (!Int32.TryParse(userInput, out id)) { Console.WriteLine("Invalid id ,Please enter the valid id in positive integer"); return; } Console.WriteLine("Enter Name"); string name = Console.ReadLine(); Console.WriteLine("Enter Mark1"); userInput = Console.ReadLine(); int mark1; if (!Int32.TryParse(userInput, out mark1) || mark1 < 0 || mark1 > 100) { Console.WriteLine("Invalid Mark,Please enter the valid mark between mark<0&&mark>100"); return; } Console.WriteLine("Enter Mark2"); userInput = Console.ReadLine(); int mark2; if (!Int32.TryParse(userInput, out mark2) || mark2 < 0 || mark2 > 100) { Console.WriteLine("Invalid Mark,Please enter the valid mark between mark<0&&mark>100"); return; } Console.WriteLine("Enter Mark3"); userInput = Console.ReadLine(); int mark3; if (!Int32.TryParse(userInput, out mark3) || mark3 < 0 || mark3 > 100) { Console.WriteLine("Invalid Mark,Please enter the valid mark between mark<0&&mark>100"); return; } Console.WriteLine("Enter School Name"); string schoolName = Console.ReadLine(); Console.WriteLine("Enter District"); string district = Console.ReadLine(); Student student = new Student(id, name, mark1, mark2, mark3, schoolName, district); db.AddStudent(student); }
public void AddStudent(Student student) { students.Add(student); }
private void AddTestStudents() { Random random = new Random(); int AddedNoOfStudentsCount = 10; int studentCount = db.Count; for (int i = 1; i <= AddedNoOfStudentsCount; i++) { int studentId = studentCount + i; string name = "Student" + studentId.ToString(); int mark1 = random.Next(90, 100); int mark2 = random.Next(80, 90); int mark3 = random.Next(70, 90); string schoolName = "School" + random.Next(10).ToString(); string district = "District" + random.Next(20).ToString(); Student student = new Student(id: studentId, name: name, mark1: mark1, mark2: mark2, mark3: mark3, schoolName: schoolName, district: district); db.AddStudent(student); } }