Finalvanshviraj
Finalvanshviraj
Finalvanshviraj
2. Student Class:
The Student class represents individual students in the system.
It has attributes such as name and rollNumber .
The class includes a constructor to initialize a Student object
with a name and roll number, as well as getter methods to
retrieve these attributes.
3. Methods in AttendanceSystem:
addStudent(): Prompts the user to input the name and roll
number of a student, creates Student object, and adds it to the
a array of students.
removeStudent(): Asks the user for the roll number of the
student to be removed, finds the index of the student in the
array, removes the student if found, and adjusts the array
accordingly.
viewStudents(): Displays the list of students currently present in
the system, showing their names and roll numbers.
findStudentIndex(int rollNumber): Searches for a student in
the array based on their roll number and returns the index if
found, otherwise returns -1.
4. Array of Students:
The program maintains an array students to store instances of
the Student class.
The size of the array is set to accommodate a maximum of
60 students (
private static Student[] students =
new Student[60]).
The variable studentCount keeps track of the number of
students currently stored in the array.
5. Input Validation:
The program validates user input to ensure correctness. For
example, it checks if the entered roll number is valid or if
the student to be removed exists in the system.
6. User Interface:
The user interface is text-based, displaying options and prompts
to the user via the console.
Users interact with the program by entering choices and
providing input when prompted.
Overall, this program provides a simple yet effective way to manage student
attendance data through basic CRUD (Create, Read, Update, Delete)
operations.
import java.util.Scanner;
maximum of 60 students
int choice;
do {
System.out.println("4. Exit");
choice = scanner.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
removeStudent();
break;
case 3:
viewStudents();
break;
case 4:
break;
default:
System.out.println("Invalid Choice!");
scanner.close();
+;
if (index != -1) {
studentCount--;
} else {
{ if (studentCount == 0) {
} else {
System.out.println("\nStudent List:");
if (students[i].getRollNumber() == rollNumber)
{ return i;
return -1;
}
class Student {
{ this.name = name;
this.rollNumber = rollNumber;
{ return name;
{ return rollNumber;
}
Output :-
Add Student: Allows users to input the name and roll number of a student
and adds them to the system.
View Students: Displays the list of students currently present in the system, showing their
names and roll numbers.
Remove Student: Enables users to remove a student from the system by entering the roll
number of the student they wish to remove.
Conclusion: