-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
83 lines (66 loc) · 2.72 KB
/
Copy pathMain.java
File metadata and controls
83 lines (66 loc) · 2.72 KB
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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
StudentService service = new StudentService();
while (true) {
System.out.println("\n===== Student Management System =====");
System.out.println("1. Add Student");
System.out.println("2. View Students");
System.out.println("3. Search Student");
System.out.println("4. Update Student");
System.out.println("5. Delete Student");
System.out.println("6. Exit");
System.out.print("Enter choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter ID: ");
int id = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
sc.nextLine();
System.out.print("Enter Course: ");
String course = sc.nextLine();
service.addStudent(new Student(id, name, age, course));
break;
case 2:
service.viewStudents();
break;
case 3:
System.out.print("Enter ID to search: ");
Student s = service.searchStudent(sc.nextInt());
if (s != null)
System.out.println(s);
else
System.out.println("Student Not Found!");
break;
case 4:
System.out.print("Enter ID to update: ");
int uid = sc.nextInt();
sc.nextLine();
System.out.print("New Name: ");
String newName = sc.nextLine();
System.out.print("New Age: ");
int newAge = sc.nextInt();
sc.nextLine();
System.out.print("New Course: ");
String newCourse = sc.nextLine();
service.updateStudent(uid, newName, newAge, newCourse);
break;
case 5:
System.out.print("Enter ID to delete: ");
service.deleteStudent(sc.nextInt());
break;
case 6:
System.out.println("Exiting...");
System.exit(0);
default:
System.out.println("Invalid Choice!");
}
}
}
}