Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RoomUtility {
- private static int numberOfRooms;
- public static void detailsReport(ArrayList<Room> rooms){
- System.out.println("Room Count Details Report");
- }
- private static final int ROOM_DOES_NOT_EXIST = -1;
- private static ArrayList<Room> rooms = new ArrayList();
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- String menu = "------------------------n- CIS Room Bookingn"
- + "------------------------n"
- + "Choose an option:n"
- + "1) Add Roomn"
- + "2) Reserve Roomn"
- + "3) Release Roomn"
- + "4) Show Roomsn"
- + "5) Show Room Details Reportn"
- + "6) Exit";
- int selection = 0;
- while (selection != 6) {
- System.out.println(menu);
- selection = input.nextInt();
- input.nextLine();
- switch (selection) {
- case 1:
- addRoom();
- break;
- case 2:
- reserveRoom();
- break;
- case 3:
- releaseRoom();
- break;
- case 4:
- showRooms();
- break;
- case 5:
- RoomUtility.detailsReport(rooms);
- break;
- default:
- System.out.println("Invalid option.");
- }
- }
- }
- public static int getRoomNumberIfExists(int roomNumber) {
- int index = -1;
- for (int i = 0; i < rooms.size(); i++) {
- if (rooms.get(i).getRoomNumber() == roomNumber) {
- index = i;
- }
- }
- return index;
- }
- /**
- * This method will allow the user to add a new room to the collection of rooms.
- *
- */
- public static void addRoom() {
- //***********************************************************
- //Ask which room number the user wants to add
- //***********************************************************
- Room room = null;
- Scanner input = new Scanner(System.in);
- System.out.print("Enter room number: ");
- int roomNumber = input.nextInt();
- input.nextLine();
- //***********************************************************
- //Check to see if the room already exists
- //***********************************************************
- int roomNumberIndex = getRoomNumberIfExists(roomNumber);
- //If the room does not already exist.
- if (roomNumberIndex == ROOM_DOES_NOT_EXIST) {
- roomNumberIndex = rooms.size();
- boolean finished = false;
- do {
- System.out.print("What type of room is this?n" + "1) Add Roomn"
- + "2) Computer Labn"
- + "3) Board Roomn"
- + "4) Biology labn");
- String choice = input.nextLine();
- //***********************************************************
- //Based on the user input, create the correct type of room.
- //***********************************************************
- switch (choice) {
- case "1":
- room = new Room();
- finished = true;
- break;
- case "2":
- room = new ComputerRoom();
- finished = true;
- break;
- case "3":
- room = new BoardRoom();
- room.getBoardRoomDetails();
- finished = true;
- break;
- case "4":
- room = new BiologyLab();
- finished = true;
- break;
- default:
- System.out.println("Invalid option");
- }
- } while (!finished);
- //Set the details for the room
- room.setRoomNumber(roomNumber);
- //Note the correct method will be invoked based on which type of room was created above.
- room.getRoomDetailsFromUser();
- //Add the room to the collection of rooms. Note that as long as an object 'is a' Room
- //(all of the types of rooms above are rooms), then it can be added to the collection of
- //rooms.
- rooms.add(room);
- } else {
- String choice = "";
- System.out.println("Room already exists. Do you want to continue? (Y/N)");
- choice = input.nextLine();
- //If the user wants to continue, invoke the method to change the value of attributes in
- //the room
- if (choice.equalsIgnoreCase("y")) {
- rooms.get(roomNumberIndex).getRoomDetailsFromUser();
- }
- }
- }
- /**
- * This method will allow the user to reserve a room.
- */
- public static void reserveRoom() {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the room number you would like to book");
- int roomNumber = input.nextInt();
- input.nextLine();
- //Check to see if the room exists.
- int roomNumberIndex = getRoomNumberIfExists(roomNumber);
- if (roomNumberIndex < 0) {
- System.out.println("This room does not exist");
- } else {
- //Put the room from the ArrayList into a local variable.
- Room room = rooms.get(roomNumberIndex);
- if (!room.isReserved()) {
- room.reserveThisRoom();
- } else {
- System.out.println("This room is already booked!");
- }
- }
- }
- public static void releaseRoom() {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter the room number you would like to release");
- int roomNumber = input.nextInt();
- input.nextLine();
- //Check if the room exists.
- int roomNumberIndex = getRoomNumberIfExists(roomNumber);
- if (roomNumberIndex < 0) {
- System.out.println("This room does not exist");
- } else {
- //Put the room from the ArrayList into a local variable.
- Room room = rooms.get(roomNumberIndex);
- //If the room is reserved, allow them to release.
- if (room.isReserved()) {
- room.releaseThisRoom();
- } else {
- System.out.println("This room is not booked!");
- }
- }
- }
- /**
- * Show the details for each room
- */
- public static void showRooms() {
- System.out.println("");
- System.out.println("------------------------");
- System.out.println("- Room List");
- System.out.println("------------------------");
- if(rooms.size() == 0){
- System.out.println("There are no rooms.");
- }
- for (int i = 0; i < rooms.size(); i++) {
- System.out.println(rooms.get(i));
- }
- System.out.println("");
- }
- Scanner input = new Scanner(System.in);
- private int roomNumber;
- private int numberOfSeats;
- private String reservedBy = "";
- private boolean reserved;
- private boolean hasSmartBoard;
- private int recliners;
- private int coffeeMaker;
- public void getRoomDetailsFromUser() {
- System.out.print("Enter number of seats: ");
- numberOfSeats = input.nextInt();
- input.nextLine();
- System.out.print("Does this classroom have a smart board? (Y/N)");
- hasSmartBoard = input.nextLine().equalsIgnoreCase("y");
- }
- public boolean isHasSmartBoard() {
- return hasSmartBoard;
- }
- public void setHasSmartBoard(boolean hasSmartBoard) {
- this.hasSmartBoard = hasSmartBoard;
- }
- public int getNumberOfSeats() {
- return numberOfSeats;
- }
- public void setNumberOfSeats(int numberOfSeats) {
- this.numberOfSeats = numberOfSeats;
- }
- public String getReservedBy() {
- return reservedBy;
- }
- public void setReservedBy(String reservedBy) {
- this.reservedBy = reservedBy;
- }
- public boolean isReserved() {
- return reserved;
- }
- public void setReserved(boolean reserved) {
- this.reserved = reserved;
- }
- public void setRoomNumber(int roomNumber) {
- this.roomNumber = roomNumber;
- }
- public int getRoomNumber() {
- return roomNumber;
- }
- public int getRecliners() {
- return recliners;
- }
- public void setRecliners(int recliners) {
- this.recliners = recliners;
- }
- public int getCoffeeMaker() {
- return coffeeMaker;
- }
- public void setCoffeeMaker(int coffeeMaker) {
- this.coffeeMaker = coffeeMaker;
- }
- public void reserveThisRoom() {
- this.reserved = true;
- System.out.println("Enter the name of the person reserving this room: ");
- reservedBy = input.nextLine();
- }
- public void releaseThisRoom() {
- this.reserved = false;
- reservedBy = "";
- System.out.println("Room has been releasedn");
- }
- public void getBoardRoomDetails(){
- System.out.println("How many Lazy Boy Recliners?");
- recliners= input.nextInt();
- System.out.println("How many coffee makers?");
- coffeeMaker = input.nextInt();
- }
- public String toString() {
- String output = "n"
- + "nRoom Number: " + roomNumber
- + "nNumber of Seats: " + numberOfSeats
- + "nReserved By: " + reservedBy
- + "nReserved: " + reserved
- + "nSmart Board: " + hasSmartBoard
- + "nLazy Boy Recliners "+ recliners
- + "nCoffee Makers "+coffeeMaker;
- return output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement