-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
104 lines (72 loc) · 3.14 KB
/
Main.java
File metadata and controls
104 lines (72 loc) · 3.14 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
StudentManager manager = new StudentManager();
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.println("Enter your choice");
int choice = scanner.nextInt();
switch (choice){
case 1:
scanner.nextLine();
System.out.println("Enter ID");
int id = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter Name: ");
String name = scanner.nextLine();
System.out.println("Enter Age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.println("Enter Course");
String course = scanner.nextLine();
Student student = new Student(id,name,age, course);
manager.addStudent(student);
break;
case 2:
manager.viewStudents();
break;
case 3:
System.out.println("Enter student ID to search: ");
int searchId = scanner.nextInt();
Student foundStudent = manager.searchStudentById(searchId);
if(foundStudent == null){
System.out.println("Student Not Found");
}else {
System.out.println(foundStudent);
}
break;
case 4:
System.out.println("Enter student ID:");
int updateId = scanner.nextInt();
System.out.println("Enter New Name");
String newName = scanner.nextLine();
System.out.println("Enter New Age");
int newAge = scanner.nextInt();
System.out.println("Enter New Course");
String newCourse = scanner.nextLine();
manager.updateStudent(updateId, newName, newAge, newCourse);
break;
case 5:
System.out.println("Enter Student ID to delete");
int deleteID = scanner.nextInt();
manager.deleteStudent(deleteID);
break;
case 6:
System.out.println("Exiting the program....");
scanner.close();
System.exit(0); // Terminates JVM
break;
default:
System.out.println("Invalid Choice");
break;
}
}
}
}