-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
59 lines (54 loc) · 2.18 KB
/
Main.java
File metadata and controls
59 lines (54 loc) · 2.18 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
import java.util.Scanner;
public class Main{
public static void main(String Args[]){
Scanner sc=new Scanner(System.in);
StudentManager manager = new StudentManager();
manager.loadFromFile();
while(true){
System.out.println("1. Add Student");
System.out.println("2. View Students");
System.out.println("3. Search Student");
System.out.println("4. Delete Student");
System.out.println("5. Exit");
System.out.print("Enter your choice: ");
int choice = sc.nextInt();
sc.nextLine(); // Consume newline
switch(choice){
case 1:
System.out.print("Enter ID: ");
int id = sc.nextInt();
sc.nextLine(); // Consume newline
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Age: ");
int age = sc.nextInt();
sc.nextLine(); // Consume newline
System.out.print("Enter Course: ");
String course = sc.nextLine();
manager.addStudent(new Student(id, name, age, course));
manager.saveToFile();
break;
case 2:
manager.viewStudents();
break;
case 3:
System.out.print("Enter ID to search: ");
int searchId = sc.nextInt();
manager.searchStudent(searchId);
break;
case 4:
System.out.print("Enter ID to delete: ");
int deleteId = sc.nextInt();
manager.deleteStudent(deleteId);
manager.saveToFile();
break;
case 5:
System.out.println("Exiting...");
sc.close();
return;
default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}