-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagementApp.java
More file actions
70 lines (60 loc) · 2.61 KB
/
Copy pathStudentManagementApp.java
File metadata and controls
70 lines (60 loc) · 2.61 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
import java.util.Scanner;
public class StudentManagementApp {
public static void main(String[] args) {
StudentManagementSystem sms = new StudentManagementSystem();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("\n=== Student Management System ===");
System.out.println("1. Add Student");
System.out.println("2. Remove Student");
System.out.println("3. Search Student");
System.out.println("4. Display All Students");
System.out.println("5. Exit");
System.out.print("Choose an option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1 -> {
// Add student
System.out.print("Enter name: ");
String name = scanner.nextLine();
System.out.print("Enter roll number: ");
int rollNumber = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter grade: ");
String grade = scanner.nextLine();
if (name.isEmpty() || grade.isEmpty()) {
System.out.println("Name and grade cannot be empty.");
} else {
Student student = new Student(name, rollNumber, grade);
sms.addStudent(student);
}
}
case 2 -> {
// Remove student
System.out.print("Enter roll number to remove: ");
int rollToRemove = scanner.nextInt();
sms.removeStudent(rollToRemove);
}
case 3 -> {
// Search student
System.out.print("Enter roll number to search: ");
int rollToSearch = scanner.nextInt();
Student foundStudent = sms.searchStudent(rollToSearch);
if (foundStudent != null) {
System.out.println(foundStudent);
}
}
case 4 -> // Display all students
sms.displayAllStudents();
case 5 -> {
// Exit
System.out.println("Exiting the application. Goodbye!");
scanner.close();
return;
}
default -> System.out.println("Invalid choice. Please try again.");
}
}
}
}