Untitled

 avatar
unknown
plain_text
a year ago
11 kB
5
Indexable
// @author imran

import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.ArrayList;
import java.time.format.DateTimeFormatter;
import java.time.LocalDate;

public class ClassroomBookingApp {

    // Create new Scanner object
    private static final Scanner INPUT = new Scanner(System.in);

    // Define the ArrayLists as static fields (so can be accessed by all methods instead of main method)
    private static ArrayList<Classroom> classrooms = new ArrayList<>();
    private static ArrayList<Lecturer> lecturers = new ArrayList<>();
    private static ArrayList<Booking> bookings = new ArrayList<>();

    // Display Main Menu
    private static void printMainMenu() {
        System.out.println("*".repeat(50));
        System.out.println("Welcome to Classroom Booking Application");
        System.out.println("*** Main Menu ***");
        System.out.println("1. Manage Classrooms");
        System.out.println("2. Manage Lecturers");
        System.out.println("3. Manage Bookings");
        System.out.println("4. Generate Reports");
        System.out.println("0. Exit");
        System.out.println("*".repeat(50));
    }

    // Display Classrooms Menu
    private static void printClassroomsMenu() {
        System.out.println("*".repeat(50));
        System.out.println("Welcome to Classroom Booking Application");
        System.out.println("*** Classrooms Menu ***");
        System.out.println("1. Create Classroom");
        System.out.println("2. Update Classroom");
        System.out.println("3. Delete Classroom");
        System.out.println("4. View All Classrooms");
        System.out.println("5. Back to Main Menu");
        System.out.println("*".repeat(50));
    }

    private static void printLecturersMenu() {
        System.out.println("*".repeat(50));
        System.out.println("Welcome to Classroom Booking Application");
        System.out.println("*** Lecturers Menu ***");
        System.out.println("1. Add Lecturer");
        System.out.println("2. Edit Lecturer");
        System.out.println("3. Remove Lecturer");
        System.out.println("4. View All Lecturers");
        System.out.println("5. Back to Main Menu");
        System.out.println("*".repeat(50));
    }

    private static void printBookingsMenu() {
        System.out.println("*".repeat(50));
        System.out.println("Welcome to Classroom Booking Application");
        System.out.println("*** Bookings Menu ***");
        System.out.println("1. Make a Booking");
        System.out.println("2. Cancel a Booking");
        System.out.println("3. View All Bookings");
        System.out.println("4. Back to Main Menu");
        System.out.println("*".repeat(50));
    }

    private static void printReportsMenu() {
        System.out.println("*".repeat(50));
        System.out.println("Welcome to Classroom Booking Application");
        System.out.println("*** Reports Menu ***");
        System.out.println("1. Generate Bookings Report by Date");
        System.out.println("2. Generate Bookings Report by Classroom");
        System.out.println("3. Generate Bookings Report by Lecturer");
        System.out.println("4. Generate Total Number of Bookings");
        System.out.println("5. Back to Main Menu");
        System.out.println("*".repeat(50));
    }

    // Get User's Menu Option Input
    private static int getOptionInput() {
        boolean validInput = false;
        int menuOption = -1;

        // First Prompt to Obtain Input
        System.out.print("Please select an option to continue: ");
        while (!validInput) {
            try {

                // Obtain Input
                menuOption = INPUT.nextInt();

                // Check Input Range
                switch (menuOption) {
                    case 0:
                    case 1:
                    case 2:
                    case 3:
                    case 4:
                        break;
                    default:
                        System.out.println("Hey! You entered an invalid option!");
                        System.out.print("Please reselect a VALID option: ");
                        continue;
                }
                validInput = true;

                // If Input Isn't Integer
            } catch (InputMismatchException e) {
                System.out.println("Hey! You entered an invalid option!");
                INPUT.next(); // Clear Invalid Input
                System.out.print("Please reselect a VALID option: ");
            }
        }
        return menuOption; // Return Valid Input
    }

    private static void manageClassroomsMenu() { //Appendix C
        boolean backToMainMenu = false;

        while (!backToMainMenu) {
            printClassroomsMenu(); //prints classroom menu

            int choice = getOptionInput();
            switch (choice) {
                case 1:
                    createClassroom();
                    break;
                case 2:
                    updateClassroom();
                    break;
                case 3:
                    deleteClassroom();
                    break;
                case 4:
                    viewAllClassrooms();
                    break;
                case 5:
                    backToMainMenu = true;
                    break;
                default:
                    System.out.println("Invalid option, please try again!");

            }
        }
    }

    private static void createClassroom() { //create classroom method
        System.out.print("Enter classroom number: ");
        int classroomNum = INPUT.nextInt();
        INPUT.nextLine(); // this is required as the integer is read and the newline character remains in the buffer. ( not required for the strings input)

        System.out.print("Enter classroom name: ");
        String classroomName = INPUT.nextLine();

        System.out.print("Enter classroom location: ");
        String classroomLocation = INPUT.nextLine();

        Classroom newRoom = new Classroom(classroomNum, classroomName, classroomLocation);
        classrooms.add(newRoom);

        System.out.println("New Classroom created");

    }

    private static void updateClassroom() { //update classroom method
        System.out.print("Enter classroom number to update: ");
        int classroomNum = INPUT.nextInt();
        INPUT.nextLine();

        Classroom roomToUpdate = null;
        for (Classroom existingClassroom : classrooms) {
            if (existingClassroom.getClassroomNumber() == classroomNum) {
                roomToUpdate = existingClassroom;
                break;
            }
        }

        if (roomToUpdate == null) {
            System.out.println("Error: Invalid classroom number!");
            return;
        }
        System.out.print("Update classroom name: "); // get user input for new details
        String newClassroomName = INPUT.nextLine();

        System.out.print("Update classroom location: ");
        String newClassroomLocation = INPUT.nextLine();

        roomToUpdate.setClassroomName(newClassroomName); //updates the ClassroomName var created in Classroom file
        roomToUpdate.setClassroomLocation(newClassroomLocation);

        System.out.println("Classroom '" + classroomNum + "' updated!");
    }

    private static void deleteClassroom() { //delete classroom method
        System.out.print("Enter classroom number: ");
        int classroomNum = INPUT.nextInt();
        INPUT.nextLine();

        Classroom roomToDelete = null;
        for (Classroom existingClassroom : classrooms) {
            if (existingClassroom.getClassroomNumber() == classroomNum) {
                roomToDelete = existingClassroom;
                break;
            }
        }

        if (roomToDelete == null) {
            System.out.println("Error: classroom number '" + classroomNum + "' does not exist!");
        } else {
            classrooms.remove(roomToDelete); //remove method 
            System.out.println("Classroom '" + classroomNum + "' deleted!");
        }
    }

    private static void viewAllClassrooms() {
        if (classrooms.isEmpty()) { //helps to check if list is empty
            System.out.println("No classrooms created.");
        } else {
            System.out.println("** Classroom List **");
            for (Classroom viewClassroom : classrooms) {
                System.out.println("Classroom Number: " + viewClassroom.getClassroomNumber() + ", Name: " + viewClassroom.getClassroomName() + ", Location: " + viewClassroom.getClassroomLocation());
            }
        }
    }
    
    
     private static void manageLecturersMenu() { //Appendix D
        boolean backToMainMenu = false;

        while (!backToMainMenu) {
            printClassroomsMenu(); //prints classroom menu

            int choice = getOptionInput();
            switch (choice) {
                case 1:
                    addLecturer();
                    break;
                case 2:
                    editLecturer();
                    break;
                case 3:
                    removeLecturer();
                    break;
                case 4:
                    viewAllLecturers();
                    break;
                case 5:
                    backToMainMenu = true;
                    break;
                default:
                    System.out.println("Invalid option, please try again!");

            }
        }
    }
     
     private static void addLecturer() { //create lecturer method
         System.out.print("Enter lecturer ID: ");
         int lecturerId = INPUT.nextInt();
         INPUT.nextLine();
         
         System.out.print("Enter lecturer full name: ");
         String fullName = INPUT.nextLine();
         
         System.out.print("Enter lecturer contact number: ");
         String contactNumber = INPUT.nextLine();
         
         System.out.print("Enter lecturer email: ");
         String emailAddress = INPUT.nextLine();
         
         Lecturer newLecturer = new Lecturer(lecturerId, fullName, contactNumber, emailAddress);
         lecturers.add(newLecturer);
         
         System.out.println("New lecturer added!");
         
     }
     
      private static void editLecturer() { //edit lecturer method
          
      }

    // Main Method
    public static void main(String[] args) {

        // Display Main Menu
        printMainMenu();

        // Obtain Main Menu Option from User
        int menuOption = getOptionInput();

        switch (menuOption) {
            case 1: // Manage Classrooms
                manageClassroomsMenu();
                break;
            case 2: // Manage Lecturers
                // manageLecturersMenu();
                break;
            case 3: // Manage Bookings
                // manageBookingsMenu();
                break;
            case 4: // Generate Reports
                // manageReportsMenu();
                break;
            case 0: // Exit
                break;
        }

    }

}
Editor is loading...
Leave a Comment