-
Notifications
You must be signed in to change notification settings - Fork 1
/
StudentDetailsManagement.java
74 lines (62 loc) · 3.07 KB
/
StudentDetailsManagement.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
73
74
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class StudentDetailsManagement {
public static void main(String[] args) {
Map<String, String> studentDetails = new HashMap<>();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Select an action:");
System.out.println("1. Add student detail");
System.out.println("2. Remove student detail");
System.out.println("3. Update student detail");
System.out.println("4. View student details");
System.out.println("5. Exit");
int choice = scanner.nextInt();
scanner.nextLine();
switch (choice) {
case 1:
System.out.print("Enter the student ID: ");
String studentId = scanner.nextLine();
System.out.print("Enter the student name: ");
String studentName = scanner.nextLine();
studentDetails.put(studentId, studentName);
System.out.println("Student detail added successfully.");
break;
case 2:
System.out.print("Enter the student ID to remove: ");
String studentIdToRemove = scanner.nextLine();
studentDetails.remove(studentIdToRemove);
System.out.println("Student detail removed successfully.");
break;
case 3:
System.out.print("Enter the student ID to update: ");
String studentIdToUpdate = scanner.nextLine();
if (studentDetails.containsKey(studentIdToUpdate)) {
System.out.print("Enter the new student name: ");
String updatedStudentName = scanner.nextLine();
studentDetails.put(studentIdToUpdate, updatedStudentName);
System.out.println("Student detail updated successfully.");
} else {
System.out.println("Student detail not found.");
}
break;
case 4:
System.out.println("Student Details:");
for (Map.Entry<String, String> entry : studentDetails.entrySet()) {
String studentIdDetail = entry.getKey();
String studentNameDetail = entry.getValue();
System.out.println("Student ID: " + studentIdDetail + ", Student Name: " + studentNameDetail);
}
break;
case 5:
System.out.println("Exiting the program.");
System.exit(0);
default:
System.out.println("Invalid choice. Please try again.");
}
System.out.println();
scanner.close();
}
}
}