Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.util.Scanner;
- public class BookingSystem {
- private static Scanner input = new Scanner(System.in);
- private static final Room[] rooms = new Room[5];
- public static void main(String[] args) throws Exception {
- loadRooms();
- String choice = " ";
- do {
- System.out.println("\n-- Main Menu --"
- +"1 - Show Available Rooms"
- +"2 - Book a Room"
- +"3 - Cancel a Room"
- +"Q - Quit"
- +"Please make a choice : ");
- choice = input.next().toUpperCase();
- switch (choice) {
- case "1" : {
- displayRooms();
- break;
- }
- case "2" : {
- cancelRoom();
- break;
- }
- }
- } while (!choice.equals("Q"));
- System.out.println("-- Farewell --");
- }
- private static void cancelRoom() {
- // TODO Auto-generated method stub
- }
- private static void loadRooms() throws FileNotFoundException {
- Scanner file = new Scanner(new FileReader("Rooms.txt"));
- int index = 0;
- while (file.hasNext()) {
- int Num = Integer.parseInt(file.nextLine());
- String type = file.nextLine();
- String price = file.nextLine();
- Boolean hasBalcony = Boolean.parseBoolean(file.nextLine()); //converts the integers and booleans respectively
- Boolean hasLounge = Boolean.parseBoolean(file.nextLine());
- String emailData = file.nextLine(); //read the line of email as a String and split into integers
- String[] semail = emailData.split(" ");
- int [] email = new int[10];
- for (int i=0; i<semail.length; i++) {
- email[i] = Integer.parseInt(semail[i]);
- }
- rooms[index] = new Room(Num, type, price, hasBalcony, hasLounge, email); //Constructor call which creates a series of Room Objects
- index++;
- }
- file.close();
- }
- private static void displayRooms() {
- System.out.println("\n -- Rooms Available --");
- for (int i=0; i<rooms.length; i++) { //for loop to loop over the rooms
- System.out.println(rooms[i].toString()); //calls the toString to the room class
- }
- }
- @SuppressWarnings("unused")
- private static void orderRooms() { //prompts the user to select a room number and to enter their email
- displayRooms();
- System.out.print("Enter Room Number: ");
- int roomNum = input.nextInt();
- System.out.print("Enter eMail: ");
- int email = input.nextInt();
- rooms[roomNum-1].order(email);
- }
- private static void cancelRooms() {
- System.out.println("\n-- Cancel a Room --");
- System.out.print("Enter room number; ");
- int roomNum = input.nextInt();
- Boolean orderFound = false; //calls the order method from the Room class
- for (int i=0; i<rooms.length; i++) {
- if (rooms[i].getRoomNum() == roomNum) {
- int email = 0;
- if (rooms[i].cancel(email)) {
- orderFound = true;
- }
- }
- }
- if (!orderFound) { //loops to find the room
- System.out.println("There doesnโt appear to be a booking on this room. ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement