-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
154 lines (100 loc) · 4.75 KB
/
Copy pathMain.java
File metadata and controls
154 lines (100 loc) · 4.75 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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==========================================");
System.out.println(" STUDENT MANAGEMENT SYSTEM");
System.out.println("==========================================");
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 your choice: ");
int choice = sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("\n------ Add Student ------");
System.out.print("Enter ID: ");
int id = sc.nextInt();
sc.nextLine();
System.out.print("Enter Name: ");
String name = sc.nextLine();
System.out.print("Enter Branch: ");
String branch = sc.nextLine();
int year;
while (true) {
System.out.print("Enter Year (1-4): ");
year = sc.nextInt();
if (year >= 1 && year <= 4) {
break;
}
System.out.println("Invalid Year! Please enter between 1 and 4.");
}
sc.nextLine();
System.out.print("Enter Phone: ");
String phone = sc.nextLine();
Student student = new Student(id, name, branch, year, phone);
service.addStudent(student);
break;
case 2:
service.viewStudents();
break;
case 3:
System.out.print("Enter Student ID to Search: ");
int searchId = sc.nextInt();
service.searchStudent(searchId);
break;
case 4:
System.out.print("Enter Student ID to Update: ");
int updateId = sc.nextInt();
sc.nextLine();
System.out.print("Enter New Name: ");
String newName = sc.nextLine();
System.out.print("Enter New Branch: ");
String newBranch = sc.nextLine();
int newYear;
while (true) {
System.out.print("Enter New Year (1-4): ");
newYear = sc.nextInt();
if (newYear >= 1 && newYear <= 4) {
break;
}
System.out.println("Invalid Year!");
}
sc.nextLine();
System.out.print("Enter New Phone: ");
String newPhone = sc.nextLine();
service.updateStudent(updateId, newName, newBranch, newYear, newPhone);
break;
case 5:
System.out.print("Enter Student ID to Delete: ");
int deleteId = sc.nextInt();
sc.nextLine();
System.out.print("Are you sure? (yes/no): ");
String confirm = sc.nextLine();
if (confirm.equalsIgnoreCase("yes")) {
service.deleteStudent(deleteId);
} else {
System.out.println("Delete Cancelled.");
}
break;
case 6:
System.out.println("\n==========================================");
System.out.println(" Thank You for using");
System.out.println(" STUDENT MANAGEMENT SYSTEM");
System.out.println("------------------------------------------");
System.out.println(" Developed by: Thota Usha Laharika");
System.out.println("==========================================");
sc.close();
System.exit(0);
default:
System.out.println("Invalid Choice! Please try again.");
}
}
}
}