-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
106 lines (90 loc) · 4.22 KB
/
Main.java
File metadata and controls
106 lines (90 loc) · 4.22 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
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
106
import java.util.*;
class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
StudentOperations operations = new StudentOperations();
int choice;
do {
System.out.println("\nMenu:");
System.out.println("1. Add Student");
System.out.println("2. Display All Students");
System.out.println("3. Search Student by PRN");
System.out.println("4. Search Student by Name");
System.out.println("5. Search Student by Branch");
System.out.println("6. Update Student");
System.out.println("7. Delete Student");
System.out.println("8. Exit");
System.out.print("Enter your choice: ");
choice = Integer.parseInt(scan.nextLine());
switch (choice) {
case 1:
System.out.print("Enter Name: ");
String name = scan.nextLine();
System.out.print("Enter PRN: ");
int prn = Integer.parseInt(scan.nextLine()); // FIXED: Missing semicolon
System.out.print("Enter Branch: ");
String branch = scan.nextLine();
System.out.print("Enter Batch: ");
String batch = scan.nextLine();
System.out.print("Enter CGPA: ");
float cgpa = Float.parseFloat(scan.nextLine());
operations.addStudent(new Student(name, prn, branch, batch, cgpa));
break; // FIXED: Ensured break is properly placed
case 2:
operations.displayStudents();
break;
case 3:
System.out.print("Enter PRN to search: ");
prn = Integer.parseInt(scan.nextLine());
Student student = operations.searchStudentByPRN(prn);
if (student != null)
student.display();
else
System.out.println("Student not found.");
break;
case 4:
System.out.print("Enter Name to search: ");
name = scan.nextLine();
List<Student> studentsByName = operations.searchStudentByName(name);
if (!studentsByName.isEmpty())
studentsByName.forEach(Student::display);
else
System.out.println("No students found with this name.");
break;
case 5:
System.out.print("Enter Branch to search: ");
branch = scan.nextLine();
List<Student> studentsByBranch = operations.searchStudentByBranch(branch);
if (!studentsByBranch.isEmpty())
studentsByBranch.forEach(Student::display);
else
System.out.println("No students found in this branch.");
break;
case 6:
System.out.print("Enter PRN to update: ");
prn = Integer.parseInt(scan.nextLine());
System.out.print("Enter new Name: ");
name = scan.nextLine();
System.out.print("Enter new Branch: ");
branch = scan.nextLine();
System.out.print("Enter new Batch: ");
batch = scan.nextLine();
System.out.print("Enter new CGPA: ");
cgpa = Float.parseFloat(scan.nextLine());
operations.updateStudent(prn, name, branch, batch, cgpa);
break;
case 7:
System.out.print("Enter PRN to delete: ");
prn = Integer.parseInt(scan.nextLine());
operations.deleteStudent(prn);
break;
case 8:
System.out.println("Exiting program...");
break;
default:
System.out.println("Invalid choice! Please try again.");
}
} while (choice != 8);
scan.close();
}
}