Attendance Management System

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

Attendance Management System

This Java project is of Attendance Management System. It allows users to add


students, remove students, and view the list of students. The program utilizes a
Student class to represent individual students with attributes such as name and
roll number.

1. Main Class - AttendanceSystem:


 The AttendanceSystem class serves as the main class of the
program.
 It contains the main method where the program execution begins.
 The main method presents a menu-driven interface to the user,
allowing them to choose from various options like adding a
student, removing a student, viewing the list of students, or exiting
the program.
 It utilizes a Scanner object to accept user input.
 The program runs in a loop until the user chooses to exit.

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 a Student object, and adds it to the 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;

public class AttendanceSystem {

private static Scanner scanner = new Scanner(System.in);


private static Student[ ] students = new Student[60]; // Assuming a

maximum of 60 students

private static int studentCount = 0;

public static void main(String[] args) {

int choice;

do {

System.out.println("\nAttendance Management System");

System.out.println("1. Add Student");

System.out.println("2. Remove Student");

System.out.println("3. View Students");

System.out.println("4. Exit");

System.out.print("Enter your choice: ");

choice = scanner.nextInt();

scanner.nextLine(); // Consume newline character

switch (choice) {

case 1:

addStudent();

break;

case 2:
removeStudent();

break;

case 3:

viewStudents();

break;

case 4:

System.out.println("Exiting Attendance System...");

break;

default:

System.out.println("Invalid Choice!");

} while (choice != 4);

scanner.close();

private static void addStudent() {

System.out.print("Enter student name: ");

String name = scanner.nextLine();

System.out.print("Enter student roll number: ");

int rollNumber = scanner.nextInt();

scanner.nextLine(); // Consume newline character


students[studentCount] = new Student(name, rollNumber);

studentCount++;

System.out.println("Student added successfully!");

private static void removeStudent() {

System.out.print("Enter roll number of student to remove: ");

int rollNumber = scanner.nextInt();

scanner.nextLine(); // Consume newline character

int index = findStudentIndex(rollNumber);

if (index != -1) {

for (int i = index; i < studentCount - 1; i++) {

students[i] = students[i + 1];

studentCount--;

System.out.println("Student removed successfully!");

} else {

System.out.println("Student not found!");

private static void viewStudents() {


if (studentCount == 0) {

System.out.println("No students added yet!");

} else {

System.out.println("\nStudent List:");

for (int i = 0; i < studentCount; i++) {

System.out.println("Name: " + students[i].getName() + ", Roll

Number: " + students[i].getRollNumber());

private static int findStudentIndex(int rollNumber) {

for (int i = 0; i < studentCount; i++) {

if (students[i].getRollNumber() == rollNumber) {

return i;

return -1;

class Student {
private String name;

private int rollNumber;

public Student(String name, int rollNumber) {

this.name = name;

this.rollNumber = rollNumber;

public String getName() {

return name;

public int getRollNumber() {

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:-
The Attendance Management System program allows users to
efficiently manage student attendance records. It provides
functionalities such as adding students, removing students, and
viewing the list of students. Through a user-friendly menu interface,
the program ensures ease of use. By implementing object-oriented
principles, it maintains a scalable and organized structure. This
program can be further extended and customized to meet specific
requirements in educational institutions or similar contexts.

You might also like