mirror of
https://github.com/Manoj-HV30/OOPS-lab-codes.git
synced 2026-05-16 19:35:25 +00:00
Implement Student Management System in Java
This commit is contained in:
@@ -0,0 +1,74 @@
|
|||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
public class StudentManager {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
|
||||||
|
HashSet<String> students = new HashSet<>();
|
||||||
|
Scanner sc = new Scanner(System.in);
|
||||||
|
|
||||||
|
int choice;
|
||||||
|
|
||||||
|
do {
|
||||||
|
System.out.println("\n===== Student Management System =====");
|
||||||
|
System.out.println("1. Add student name");
|
||||||
|
System.out.println("2. Display all student names");
|
||||||
|
System.out.println("3. Remove a student name");
|
||||||
|
System.out.println("4. Exit");
|
||||||
|
System.out.print("Enter your choice: ");
|
||||||
|
|
||||||
|
choice = sc.nextInt();
|
||||||
|
sc.nextLine(); // consume newline
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
System.out.print("Enter student name to add: ");
|
||||||
|
String name = sc.nextLine();
|
||||||
|
|
||||||
|
if (students.add(name)) {
|
||||||
|
System.out.println("Student added successfully.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Duplicate entry! Student already exists.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
System.out.println("\n--- Student List ---");
|
||||||
|
|
||||||
|
if (students.isEmpty()) {
|
||||||
|
System.out.println("No students in the list.");
|
||||||
|
} else {
|
||||||
|
Iterator<String> it = students.iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
System.out.println(it.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
System.out.print("Enter student name to remove: ");
|
||||||
|
String removeName = sc.nextLine();
|
||||||
|
|
||||||
|
if (students.remove(removeName)) {
|
||||||
|
System.out.println("Student removed successfully.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Student not found.");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
System.out.println("Exiting application. Goodbye!");
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
System.out.println("Invalid choice! Please try again.");
|
||||||
|
}
|
||||||
|
|
||||||
|
} while (choice != 4);
|
||||||
|
|
||||||
|
sc.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user