Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. import java.io.FileNotFoundException;
  2. import java.io.FileReader;
  3. import java.util.Scanner;
  4.  
  5. public class BookingSystem {
  6. private static Scanner input = new Scanner(System.in);
  7.  
  8. private static final Room[] rooms = new Room[5];
  9.  
  10. public static void main(String[] args) throws Exception {
  11. loadRooms();
  12.  
  13. String choice = " ";
  14.  
  15. do {
  16. System.out.println("\n-- Main Menu --"
  17. +"1 - Show Available Rooms"
  18. +"2 - Book a Room"
  19. +"3 - Cancel a Room"
  20. +"Q - Quit"
  21. +"Please make a choice : ");
  22.  
  23. choice = input.next().toUpperCase();
  24.  
  25. switch (choice) {
  26. case "1" : {
  27. displayRooms();
  28. break;
  29. }
  30. case "2" : {
  31. cancelRoom();
  32. break;
  33. }
  34.  
  35. }
  36. } while (!choice.equals("Q"));
  37. System.out.println("-- Farewell --");
  38. }
  39.  
  40. private static void cancelRoom() {
  41. // TODO Auto-generated method stub
  42.  
  43. }
  44.  
  45. private static void loadRooms() throws FileNotFoundException {
  46. Scanner file = new Scanner(new FileReader("Rooms.txt"));
  47. int index = 0;
  48.  
  49. while (file.hasNext()) {
  50. int Num = Integer.parseInt(file.nextLine());
  51. String type = file.nextLine();
  52. String price = file.nextLine();
  53. Boolean hasBalcony = Boolean.parseBoolean(file.nextLine()); //converts the integers and booleans respectively
  54. Boolean hasLounge = Boolean.parseBoolean(file.nextLine());
  55. String emailData = file.nextLine(); //read the line of email as a String and split into integers
  56. String[] semail = emailData.split(" ");
  57. int [] email = new int[10];
  58. for (int i=0; i<semail.length; i++) {
  59. email[i] = Integer.parseInt(semail[i]);
  60. }
  61. rooms[index] = new Room(Num, type, price, hasBalcony, hasLounge, email); //Constructor call which creates a series of Room Objects
  62. index++;
  63. }
  64. file.close();
  65.  
  66. }
  67.  
  68. private static void displayRooms() {
  69. System.out.println("\n -- Rooms Available --");
  70.  
  71. for (int i=0; i<rooms.length; i++) { //for loop to loop over the rooms
  72. System.out.println(rooms[i].toString()); //calls the toString to the room class
  73. }
  74. }
  75.  
  76. @SuppressWarnings("unused")
  77. private static void orderRooms() { //prompts the user to select a room number and to enter their email
  78. displayRooms();
  79.  
  80. System.out.print("Enter Room Number: ");
  81. int roomNum = input.nextInt();
  82.  
  83. System.out.print("Enter eMail: ");
  84. int email = input.nextInt();
  85.  
  86. rooms[roomNum-1].order(email);
  87. }
  88.  
  89.  
  90. private static void cancelRooms() {
  91. System.out.println("\n-- Cancel a Room --");
  92.  
  93. System.out.print("Enter room number; ");
  94. int roomNum = input.nextInt();
  95.  
  96. Boolean orderFound = false; //calls the order method from the Room class
  97. for (int i=0; i<rooms.length; i++) {
  98. if (rooms[i].getRoomNum() == roomNum) {
  99. int email = 0;
  100. if (rooms[i].cancel(email)) {
  101. orderFound = true;
  102. }
  103. }
  104. }
  105. if (!orderFound) { //loops to find the room
  106. System.out.println("There doesnโ€™t appear to be a booking on this room. ");
  107.  
  108. }
  109.  
  110. }
  111.  
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement