-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
64 lines (60 loc) · 2.5 KB
/
Main.java
File metadata and controls
64 lines (60 loc) · 2.5 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
StudentManager manager = new StudentManager();
Scanner sc = new Scanner(System.in);
while (true) {
System.out.println("\nStudent Management System");
System.out.println("1. Add Student");
System.out.println("2. View All Students");
System.out.println("3. Search Student by ID");
System.out.println("4. Update Student");
System.out.println("5. Delete Student");
System.out.println("6. Exit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
switch (choice) {
case 1:
System.out.print("Enter ID: ");
String id = sc.next();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
System.out.print("Enter Course: ");
String course = sc.next();
System.out.print("Enter Marks: ");
double marks = sc.nextDouble();
manager.addStudent(new Student(id, name, age, course, marks));
break;
case 2:
manager.displayAllStudents();
break;
case 3:
System.out.print("Enter ID to search: ");
String searchId = sc.next();
Student found = manager.searchStudentById(searchId);
if (found != null) System.out.println(found);
else System.out.println("Student not found.");
break;
case 4:
System.out.print("Enter ID to update: ");
String updateId = sc.next();
manager.updateStudent(updateId, sc);
break;
case 5:
System.out.print("Enter ID to delete: ");
String deleteId = sc.next();
manager.deleteStudent(deleteId);
break;
case 6:
System.out.println("Exiting program.");
sc.close();
return;
default:
System.out.println("Invalid choice. Try again.");
}
}
}
}