-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskno.4
105 lines (91 loc) · 2.95 KB
/
Taskno.4
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private String name;
private int rollNumber;
private String grade;
// Constructor
public Student(String name, int rollNumber, String grade) {
this.name = name;
this.rollNumber = rollNumber;
this.grade = grade;
}
// Getters
public String getName() {
return name;
}
public int getRollNumber() {
return rollNumber;
}
public String getGrade() {
return grade;
}
}
class StudentManagementSystem {
private ArrayList<Student> students;
public StudentManagementSystem() {
students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void removeStudent(Student student) {
students.remove(student);
}
public Student searchStudent(int rollNumber) {
for (Student student : students) {
if (student.getRollNumber() == rollNumber) {
return student;
}
}
return null;
}
public void displayAllStudents() {
System.out.println("All Students:");
for (Student student : students) {
System.out.println("Name: " + student.getName());
System.out.println("Roll Number: " + student.getRollNumber());
System.out.println("Grade: " + student.getGrade());
System.out.println();
}
}
}
class StudentManagementSystemApp {
public static void main(String[] args) {
StudentManagementSystem studentManagementSystem = new StudentManagementSystem();
Scanner scanner = new Scanner(System.in);
int choice;
do {
System.out.println("Student Management System Menu:");
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("Enter your choice: ");
choice = scanner.nextInt();
scanner.nextLine(); // Consume newline
switch (choice) {
case 1:
// Implement adding a student logic
break;
case 2:
// Implement removing a student logic
break;
case 3:
// Implement searching for a student logic
break;
case 4:
// Implement displaying all students logic
break;
case 5:
System.out.println("Exiting Student Management System. Goodbye!");
break;
default:
System.out.println("Invalid choice. Please try again.");
break;
}
} while (choice != 5);
scanner.close();
}
}