Cafeteria Java
Cafeteria Java
LocalTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
class Person {
protected String name;
class Cafeteria {
private ArrayList<Student> registeredStudents = new ArrayList<>();
private String[] studentIds = new String[100]; // Assuming a maximum of 100
students
private boolean[] idTickStatus = new boolean[100]; // Assuming a maximum of
100 students
switch (registrationChoice) {
case 1:
registerCafeteriaUser(input);
break;
case 2:
registerNonCafeteriaUser(input);
break;
default:
System.out.println("Invalid choice. Please enter a valid option.");
}
} catch (InputMismatchException e) {
System.out.println("An error occurred: " + e);
input.nextLine(); // Consume newline character to avoid infinite loop
}
}
if (index != -1) {
Student student = registeredStudents.get(index);
if (student.isCafeteriaUser()) {
if (!idTickStatus[index]) {
if (student.getCampus().equalsIgnoreCase("Main")) {
// Set the time zone to East Africa Time (GMT+03:00)
LocalTime currentLocalTime =
LocalTime.now(ZoneId.of("Africa/Nairobi"));
if (index != -1) {
registeredStudents.remove(index); // Remove student from the list
idTickStatus[index] = false; // Mark as not ticked
System.out.println("Student with ID " + id + " deleted successfully.");
}
else {
System.out.println("Student with ID " + id + " not found.");
}
} catch (InputMismatchException e) {
System.out.println("you entered Invalid input , integer is required:
"+e );
input.next();
}
}
int choice = 0;
do {
try {
System.out.println("\nMain Menu:");
System.out.println("1. Register new student");
System.out.println("2. ID ticking system");
System.out.println("3. Delete registered student information");
System.out.println("4. Display registered students");
System.out.println("5. Exit");
System.out.println("Enter your choice:");
choice = input.nextInt();
input.nextLine(); // Consume newline character
switch (choice) {
case 1:
cafeteria.registerStudent(input);
break;
case 2:
cafeteria.tickId(input);
break;
case 3:
cafeteria.deleteStudent(input);
break;
case 4:
cafeteria.displayRegisteredStudents();
break;
case 5:
System.out.println("Exiting program.");
break;
default:
System.out.println("Invalid choice. Please enter a valid
option.");
}
} catch (InputMismatchException e) {
System.out.println("Invalid input , integer is required: "+e );
input.next();
}
} while (choice != 5);
input.close();
}
}