0% found this document useful (0 votes)
12 views7 pages

Rehan

The document outlines an Attendance Management System implemented in Java, featuring a Student class to manage student details and an AttendanceSystem class to handle attendance records. Users can add students, mark their attendance, and view attendance records through a simple console interface. The system allows for marking attendance as present or absent and provides feedback on operations performed.

Uploaded by

ketankotane552
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views7 pages

Rehan

The document outlines an Attendance Management System implemented in Java, featuring a Student class to manage student details and an AttendanceSystem class to handle attendance records. Users can add students, mark their attendance, and view attendance records through a simple console interface. The system allows for marking attendance as present or absent and provides feedback on operations performed.

Uploaded by

ketankotane552
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

ATTENDENCE MANAGEMENT

SYSTEM

CODE :

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;

// Student class
class Student {
private int id;
private String name;

public Student(int id, String name) {


this.id = id;
this.name = name;
}

public int getId() {


return id;
}

public String getName() {


return name;
}

@Override
public String toString() {
return id + ". " + name;
}
}

// Attendance System class


class AttendanceSystem {
private ArrayList<Student> students;
private HashMap<Integer, Boolean> attendance; // Key: Student ID,
Value: Present/Absent

public AttendanceSystem() {
students = new ArrayList<>();
attendance = new HashMap<>();
}

public void addStudent(int id, String name) {


students.add(new Student(id, name));
System.out.println("Student added successfully!");
}

public void markAttendance(int id, boolean isPresent) {


if (attendance.containsKey(id)) {
System.out.println("Attendance already marked for " +
getStudentById(id));
} else {
attendance.put(id, isPresent);
System.out.println("Attendance marked for " +
getStudentById(id));
}
}

public void viewAttendance() {


if (students.isEmpty()) {
System.out.println("No students in the system.");
return;
}

System.out.println("\nAttendance Record:");
for (Student student : students) {
String status = attendance.getOrDefault(student.getId(), false)
? "Present" : "Absent";
System.out.println(student + " - " + status);
}
}

private String getStudentById(int id) {


for (Student student : students) {
if (student.getId() == id) {
return student.getName();
}
}
return "Unknown Student";
}
}

// Main class
public class AttendanceManagementSystem {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
AttendanceSystem system = new AttendanceSystem();

while (true) {
System.out.println("\nAttendance Management System:");
System.out.println("1. Add Student");
System.out.println("2. Mark Attendance");
System.out.println("3. View Attendance");
System.out.println("4. Exit");
System.out.print("Enter your choice: ");

int choice = scanner.nextInt();


scanner.nextLine(); // Consume newline

switch (choice) {
case 1:
System.out.print("Enter Student ID: ");
int id = scanner.nextInt();
scanner.nextLine(); // Consume newline
System.out.print("Enter Student Name: ");
String name = scanner.nextLine();
system.addStudent(id, name);
break;

case 2:
System.out.print("Enter Student ID to mark attendance:
");
int studentId = scanner.nextInt();
System.out.print("Mark Present? (1 for Yes, 0 for No): ");
boolean isPresent = scanner.nextInt() == 1;
system.markAttendance(studentId, isPresent);
break;

case 3:
system.viewAttendance();
break;

case 4:
System.out.println("Exiting the system. Goodbye!");
scanner.close();
return;

default:
System.out.println("Invalid choice. Please try again.");
}
}
}
}
OUTPUT :

You might also like