Repository navigation
Expand file tree
/
Copy pathStudentManagementSystem.java
More file actions
77 lines (77 loc) · 2.5 KB
/
Copy pathStudentManagementSystem.java
File metadata and controls
77 lines (77 loc) · 2.5 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
import java.util.*;
class Student{
int id;
String name;
int age;
Student(int id,String name,int age){
this.id=id;
this.name=name;
this.age=age;
}
}
public class StudentManagementSystem{
static ArrayList<Student> students =new ArrayList<>();
static Scanner sc=new Scanner(System.in);
public static void main(String[] args){
while(true){
System.out.println("/n--- Student Management System ---");
System.out.println("1.Add Student");
System.out.println("2.View Students");
System.out.println("3.Delete Students");
System.out.println("4.Exit");
System.out.println("Enter choice: ");
int choice=sc.nextInt();
switch(choice){
case 1:addStudent();
break;
case 2:viewStudents();
break;
case 3:deleteStudent();
break;
case 4:
System.out.println("Exiting: ...Thank you!");
return;
default: System.out.println(" Invalid option");
}
}
}
static void addStudent(){
System.out.print("Enter ID:");
int id=sc.nextInt();
sc.nextLine();
System.out.print("Enter Name:");
String name=sc.nextLine();
System.out.print("Enter age:");
int age=sc.nextInt();
students.add(new Student(id,name,age));
System.out.println("Student added Successfully!");
}
static void viewStudents(){
if(students.isEmpty()){
System.out.println("NO students found");
return;
}
System.out.println("\nID\tName\tAge");
for(Student s: students){
System.out.println(s.id + "\t" + s.name + "\t" + s.age);
}
}
static void deleteStudent(){
System.out.print("Enter Id to Delete: ");
int id=sc.nextInt();
Iterator<Student> it=students.iterator();
boolean found=false;
while(it.hasNext()){
Student s=it.next();
if(s.id == id){
it.remove();
found=true;
System.out.println(" Student Deleted");
break;
}
}
if(!found){
System.out.println("Student not Found.");
}
}
}