Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.76 KB | None | 0 0
  1. public class RoomUtility {
  2.  
  3. private static int numberOfRooms;
  4.  
  5. public static void detailsReport(ArrayList<Room> rooms){
  6. System.out.println("Room Count Details Report");
  7.  
  8.  
  9. }
  10.  
  11. private static final int ROOM_DOES_NOT_EXIST = -1;
  12. private static ArrayList<Room> rooms = new ArrayList();
  13.  
  14.  
  15. public static void main(String[] args) {
  16.  
  17. Scanner input = new Scanner(System.in);
  18. String menu = "------------------------n- CIS Room Bookingn"
  19. + "------------------------n"
  20. + "Choose an option:n"
  21. + "1) Add Roomn"
  22. + "2) Reserve Roomn"
  23. + "3) Release Roomn"
  24. + "4) Show Roomsn"
  25. + "5) Show Room Details Reportn"
  26. + "6) Exit";
  27. int selection = 0;
  28.  
  29.  
  30. while (selection != 6) {
  31. System.out.println(menu);
  32. selection = input.nextInt();
  33. input.nextLine();
  34. switch (selection) {
  35. case 1:
  36. addRoom();
  37. break;
  38. case 2:
  39. reserveRoom();
  40. break;
  41. case 3:
  42. releaseRoom();
  43. break;
  44. case 4:
  45. showRooms();
  46. break;
  47. case 5:
  48. RoomUtility.detailsReport(rooms);
  49. break;
  50. default:
  51. System.out.println("Invalid option.");
  52. }
  53. }
  54.  
  55. }
  56.  
  57.  
  58. public static int getRoomNumberIfExists(int roomNumber) {
  59. int index = -1;
  60. for (int i = 0; i < rooms.size(); i++) {
  61. if (rooms.get(i).getRoomNumber() == roomNumber) {
  62. index = i;
  63. }
  64. }
  65. return index;
  66. }
  67.  
  68. /**
  69. * This method will allow the user to add a new room to the collection of rooms.
  70. *
  71. */
  72. public static void addRoom() {
  73.  
  74. //***********************************************************
  75. //Ask which room number the user wants to add
  76. //***********************************************************
  77. Room room = null;
  78. Scanner input = new Scanner(System.in);
  79. System.out.print("Enter room number: ");
  80. int roomNumber = input.nextInt();
  81. input.nextLine();
  82.  
  83. //***********************************************************
  84. //Check to see if the room already exists
  85. //***********************************************************
  86.  
  87. int roomNumberIndex = getRoomNumberIfExists(roomNumber);
  88.  
  89. //If the room does not already exist.
  90. if (roomNumberIndex == ROOM_DOES_NOT_EXIST) {
  91. roomNumberIndex = rooms.size();
  92. boolean finished = false;
  93. do {
  94. System.out.print("What type of room is this?n" + "1) Add Roomn"
  95. + "2) Computer Labn"
  96. + "3) Board Roomn"
  97. + "4) Biology labn");
  98. String choice = input.nextLine();
  99.  
  100.  
  101. //***********************************************************
  102. //Based on the user input, create the correct type of room.
  103. //***********************************************************
  104.  
  105. switch (choice) {
  106. case "1":
  107. room = new Room();
  108. finished = true;
  109. break;
  110. case "2":
  111. room = new ComputerRoom();
  112. finished = true;
  113. break;
  114. case "3":
  115. room = new BoardRoom();
  116. room.getBoardRoomDetails();
  117. finished = true;
  118. break;
  119. case "4":
  120. room = new BiologyLab();
  121. finished = true;
  122. break;
  123. default:
  124. System.out.println("Invalid option");
  125.  
  126. }
  127. } while (!finished);
  128.  
  129. //Set the details for the room
  130. room.setRoomNumber(roomNumber);
  131.  
  132. //Note the correct method will be invoked based on which type of room was created above.
  133. room.getRoomDetailsFromUser();
  134.  
  135. //Add the room to the collection of rooms. Note that as long as an object 'is a' Room
  136. //(all of the types of rooms above are rooms), then it can be added to the collection of
  137. //rooms.
  138. rooms.add(room);
  139.  
  140. } else {
  141. String choice = "";
  142. System.out.println("Room already exists. Do you want to continue? (Y/N)");
  143. choice = input.nextLine();
  144.  
  145. //If the user wants to continue, invoke the method to change the value of attributes in
  146. //the room
  147. if (choice.equalsIgnoreCase("y")) {
  148. rooms.get(roomNumberIndex).getRoomDetailsFromUser();
  149. }
  150. }
  151. }
  152.  
  153.  
  154.  
  155. /**
  156. * This method will allow the user to reserve a room.
  157. */
  158.  
  159. public static void reserveRoom() {
  160.  
  161. Scanner input = new Scanner(System.in);
  162. System.out.println("Enter the room number you would like to book");
  163. int roomNumber = input.nextInt();
  164. input.nextLine();
  165.  
  166. //Check to see if the room exists.
  167. int roomNumberIndex = getRoomNumberIfExists(roomNumber);
  168. if (roomNumberIndex < 0) {
  169. System.out.println("This room does not exist");
  170. } else {
  171. //Put the room from the ArrayList into a local variable.
  172. Room room = rooms.get(roomNumberIndex);
  173. if (!room.isReserved()) {
  174. room.reserveThisRoom();
  175. } else {
  176. System.out.println("This room is already booked!");
  177. }
  178. }
  179. }
  180.  
  181. public static void releaseRoom() {
  182.  
  183. Scanner input = new Scanner(System.in);
  184. System.out.println("Enter the room number you would like to release");
  185. int roomNumber = input.nextInt();
  186. input.nextLine();
  187.  
  188. //Check if the room exists.
  189. int roomNumberIndex = getRoomNumberIfExists(roomNumber);
  190.  
  191. if (roomNumberIndex < 0) {
  192. System.out.println("This room does not exist");
  193. } else {
  194. //Put the room from the ArrayList into a local variable.
  195. Room room = rooms.get(roomNumberIndex);
  196. //If the room is reserved, allow them to release.
  197. if (room.isReserved()) {
  198. room.releaseThisRoom();
  199. } else {
  200. System.out.println("This room is not booked!");
  201. }
  202. }
  203. }
  204.  
  205. /**
  206. * Show the details for each room
  207. */
  208. public static void showRooms() {
  209. System.out.println("");
  210. System.out.println("------------------------");
  211. System.out.println("- Room List");
  212. System.out.println("------------------------");
  213. if(rooms.size() == 0){
  214. System.out.println("There are no rooms.");
  215. }
  216. for (int i = 0; i < rooms.size(); i++) {
  217. System.out.println(rooms.get(i));
  218. }
  219. System.out.println("");
  220. }
  221.  
  222. Scanner input = new Scanner(System.in);
  223. private int roomNumber;
  224. private int numberOfSeats;
  225. private String reservedBy = "";
  226. private boolean reserved;
  227. private boolean hasSmartBoard;
  228. private int recliners;
  229. private int coffeeMaker;
  230.  
  231.  
  232. public void getRoomDetailsFromUser() {
  233.  
  234. System.out.print("Enter number of seats: ");
  235. numberOfSeats = input.nextInt();
  236. input.nextLine();
  237. System.out.print("Does this classroom have a smart board? (Y/N)");
  238. hasSmartBoard = input.nextLine().equalsIgnoreCase("y");
  239.  
  240. }
  241.  
  242. public boolean isHasSmartBoard() {
  243. return hasSmartBoard;
  244. }
  245.  
  246. public void setHasSmartBoard(boolean hasSmartBoard) {
  247. this.hasSmartBoard = hasSmartBoard;
  248. }
  249.  
  250. public int getNumberOfSeats() {
  251. return numberOfSeats;
  252. }
  253.  
  254. public void setNumberOfSeats(int numberOfSeats) {
  255. this.numberOfSeats = numberOfSeats;
  256. }
  257.  
  258. public String getReservedBy() {
  259. return reservedBy;
  260. }
  261.  
  262. public void setReservedBy(String reservedBy) {
  263. this.reservedBy = reservedBy;
  264. }
  265.  
  266. public boolean isReserved() {
  267. return reserved;
  268. }
  269.  
  270. public void setReserved(boolean reserved) {
  271. this.reserved = reserved;
  272. }
  273.  
  274. public void setRoomNumber(int roomNumber) {
  275. this.roomNumber = roomNumber;
  276. }
  277.  
  278. public int getRoomNumber() {
  279. return roomNumber;
  280. }
  281.  
  282. public int getRecliners() {
  283. return recliners;
  284. }
  285.  
  286. public void setRecliners(int recliners) {
  287. this.recliners = recliners;
  288. }
  289.  
  290. public int getCoffeeMaker() {
  291. return coffeeMaker;
  292. }
  293.  
  294. public void setCoffeeMaker(int coffeeMaker) {
  295. this.coffeeMaker = coffeeMaker;
  296. }
  297.  
  298.  
  299.  
  300. public void reserveThisRoom() {
  301. this.reserved = true;
  302. System.out.println("Enter the name of the person reserving this room: ");
  303. reservedBy = input.nextLine();
  304. }
  305.  
  306.  
  307. public void releaseThisRoom() {
  308. this.reserved = false;
  309. reservedBy = "";
  310. System.out.println("Room has been releasedn");
  311.  
  312. }
  313. public void getBoardRoomDetails(){
  314. System.out.println("How many Lazy Boy Recliners?");
  315. recliners= input.nextInt();
  316. System.out.println("How many coffee makers?");
  317. coffeeMaker = input.nextInt();
  318. }
  319.  
  320. public String toString() {
  321. String output = "n"
  322. + "nRoom Number: " + roomNumber
  323. + "nNumber of Seats: " + numberOfSeats
  324. + "nReserved By: " + reservedBy
  325. + "nReserved: " + reserved
  326. + "nSmart Board: " + hasSmartBoard
  327. + "nLazy Boy Recliners "+ recliners
  328. + "nCoffee Makers "+coffeeMaker;
  329. return output;
  330. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement