-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentManagementSystem.java
72 lines (62 loc) · 2.48 KB
/
StudentManagementSystem.java
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
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
private ArrayList<String> students;
public StudentManagementSystem() {
students = new ArrayList<>();
}
public void addStudent(String studentName) {
students.add(studentName);
System.out.println("Student " + studentName + " added successfully.");
}
public void removeStudent(String studentName) {
if (students.remove(studentName)) {
System.out.println("Student " + studentName + " removed successfully.");
} else {
System.out.println("Student " + studentName + " not found.");
}
}
public void displayStudents() {
System.out.println("List of students:");
for (String student : students) {
System.out.println(student);
}
}
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
StudentManagementSystem sms = new StudentManagementSystem();
boolean running = true;
while (running) {
System.out.println("\nStudent Management System Menu:");
System.out.println("1. Add Student");
System.out.println("2. Remove Student");
System.out.println("3. Display Students");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");
int choice = scanner.nextInt();
scanner.nextLine(); // Consume newline character after nextInt()
switch (choice) {
case 1:
System.out.print("Enter student name to add: ");
String addName = scanner.nextLine();
sms.addStudent(addName);
break;
case 2:
System.out.print("Enter student name to remove: ");
String removeName = scanner.nextLine();
sms.removeStudent(removeName);
break;
case 3:
sms.displayStudents();
break;
case 4:
running = false;
System.out.println("Exiting Student Management System. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please enter a number between 1 and 4.");
}
}
scanner.close();
}
}