-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.java
91 lines (73 loc) · 3.37 KB
/
main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
StudentManagement management = new StudentManagement();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\n1. Add Student");
System.out.println("2. List Students");
System.out.println("3. Update Student");
System.out.println("4. Delete Student");
System.out.println("5. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
System.out.print("Enter ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Name: ");
String name = scanner.nextLine();
System.out.print("Enter Age: ");
int age = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Grade: ");
String grade = scanner.nextLine();
Student student = new Student(id, name, age, grade);
management.addStudent(student);
System.out.println("Student added successfully!");
break;
case 2:
System.out.println("\nList of Students:");
for (Student s : management.listStudents()) {
System.out.println(s);
}
break;
case 3:
System.out.print("Enter ID of the student to update: ");
int updateId = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter New Name: ");
String newName = scanner.nextLine();
System.out.print("Enter New Age: ");
int newAge = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter New Grade: ");
String newGrade = scanner.nextLine();
if (management.updateStudent(updateId, newName, newAge, newGrade)) {
System.out.println("Student updated successfully!");
} else {
System.out.println("Student not found.");
}
break;
case 4:
System.out.print("Enter ID of the student to delete: ");
int deleteId = scanner.nextInt();
scanner.nextLine();
if (management.deleteStudent(deleteId)) {
System.out.println("Student deleted successfully!");
} else {
System.out.println("Student not found.");
}
break;
case 5:
System.out.println("Exiting program...");
scanner.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}