-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
46 lines (38 loc) · 1.51 KB
/
Copy pathMain.java
File metadata and controls
46 lines (38 loc) · 1.51 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
import java.util.ArrayList;
import java.util.Scanner;
// Main class to run the Student Management System
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in); // Scanner for input
StudentService service = new StudentService(); // Service for creating students
ArrayList<Student> students = new ArrayList<>(); // List to store students
int choice;
do {
// Menu options
System.out.println("\n--- Student Management System ---");
System.out.println("1. Add Student");
System.out.println("2. Display Students");
System.out.println("3. Exit");
System.out.print("Enter choice: ");
choice = sc.nextInt(); // Read user's choice
sc.nextLine(); // Consume newline
switch (choice) {
case 1:
// Add a new student
students.add(service.createStudent());
break;
case 2:
// Display all students
for (Student s : students)
s.display();
break;
case 3:
// Exit program
System.out.println("Exiting...");
break;
default:
System.out.println("Invalid choice"); // Handle invalid input
}
} while (choice != 3); // Repeat menu until user chooses Exit
}
}