-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentManagementSystem.java
More file actions
130 lines (110 loc) · 4.1 KB
/
StudentManagementSystem.java
File metadata and controls
130 lines (110 loc) · 4.1 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import java.util.ArrayList;
import java.util.Scanner;
class Student {
private String rollNumber;
private String name;
private String course;
private double marks;
private String grade;
public void inputStudent(Scanner scanner) {
System.out.print("Enter student's roll number: ");
this.rollNumber = scanner.nextLine();
System.out.print("Enter student's name: ");
this.name = scanner.nextLine();
System.out.print("Enter student's course: ");
this.course = scanner.nextLine();
while (true) {
try {
System.out.print("Enter marks (0-100): ");
this.marks = Double.parseDouble(scanner.nextLine());
if (this.marks >= 0 && this.marks <= 100) {
break;
} else {
System.out.println("Invalid marks. Please enter a value between 0 and 100.");
}
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter a number for marks.");
}
}
}
public void calculateGrade() {
if (marks >= 90) {
grade = "A";
} else if (marks >= 80) {
grade = "B";
} else if (marks >= 70) {
grade = "C";
} else if (marks >= 60) {
grade = "D";
} else {
grade = "F";
}
}
public void displayStudent() {
System.out.println("Roll Number: " + rollNumber);
System.out.println("Name: " + name);
System.out.println("Course: " + course);
System.out.println("Marks: " + marks);
System.out.println("Grade: " + grade);
}
}
public class StudentManagementSystem {
private ArrayList<Student> students;
private Scanner scanner;
public StudentManagementSystem() {
students = new ArrayList<>();
scanner = new Scanner(System.in);
}
public void addStudent() {
Student student = new Student();
student.inputStudent(scanner);
student.calculateGrade();
students.add(student);
System.out.println("\nStudent record added successfully!\n");
}
public void displayAllStudents() {
if (students.isEmpty()) {
System.out.println("\nNo student records to display.\n");
return;
}
System.out.println("\n--- All Student Records ---\n");
for (Student student : students) {
student.displayStudent();
}
public void showMenu() {
while (true) {
System.out.print("\033[H\033[2J");
System.out.flush();
System.out.println(" Student Management System ");
System.out.println("1. Add a new student record");
System.out.println("2. Display all student records");
System.out.println("3. Exit");
System.out.print("Enter your choice (1-3): ");
String choice = scanner.nextLine();
switch (choice) {
case "1":
addStudent();
System.out.println("Press Enter to continue...");
scanner.nextLine();
break;
case "2":
displayAllStudents();
System.out.println("Press Enter to continue...");
scanner.nextLine();
break;
case "3":
System.out.println("\nExiting the program. Goodbye!");
return;
default:
System.out.println("\nInvalid choice. Please try again.");
System.out.println("Press Enter to continue...");
scanner.nextLine();
break;
}
}
}
public static void main(String[] args) {
StudentManagementSystem system = new StudentManagementSystem();
system.showMenu();
}
}