Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.70 KB | None | 0 0
  1. package mod7;
  2. import java.util.ArrayList;
  3. import java.util.Scanner;
  4.  
  5. import static java.lang.Integer.parseInt;
  6.  
  7. public class Driver {
  8.  
  9. // class variables (add more as needed)
  10. private static ArrayList<Ship> shipList = new ArrayList();
  11. private static ArrayList<Cruise> cruiseList = new ArrayList();
  12. private static ArrayList<Passenger> passengerList = new ArrayList();
  13. private static Scanner scnr;
  14.  
  15. public static void main(String[] args) {
  16. Scanner scnr = new Scanner(System.in);
  17. printPrompt();
  18.  
  19. System.out.print("Hello");
  20. String choice = scnr.nextLine();
  21.  
  22.  
  23. initializeShipList(); // initial ships
  24. initializeCruiseList(); // initial cruises
  25. initializePassengerList(); // initial passengers
  26.  
  27. // add loop and code here that accepts and validates user input
  28. // and takes the appropriate action. include appropriate
  29. // user feedback and redisplay the menu as needed
  30.  
  31.  
  32.  
  33.  
  34.  
  35. }
  36.  
  37. private static void printPrompt() {
  38. // TODO Auto-generated method stub
  39.  
  40. }
  41.  
  42. // hardcoded ship data for testing
  43. // Initialize ship list
  44. public static void initializeShipList() {
  45. add("Candy Cane", 20, 40, 10, 60, true);
  46. add("Peppermint Stick", 10, 20, 5, 40, true);
  47. add("Bon Bon", 12, 18, 2, 24, false);
  48. add("Candy Corn", 12, 18, 2, 24, false);
  49. }
  50.  
  51. // hardcoded cruise data for testing
  52. // Initialize cruise list
  53. public static void initializeCruiseList() {
  54. Cruise newCruise = new Cruise("Southern Swirl", "Candy Cane", "Miami", "Cuba", "Miami");
  55. cruiseList.add(newCruise);
  56. }
  57.  
  58. // hardcoded cruise data for testing
  59. // Initialize passenger list
  60. public static void initializePassengerList() {
  61. Passenger newPassenger1 = new Passenger("Neo Anderson", "Southern Swirl", "STE");
  62. passengerList.add(newPassenger1);
  63.  
  64. Passenger newPassenger2 = new Passenger("Trinity", "Southern Swirl", "STE");
  65. passengerList.add(newPassenger2);
  66.  
  67. Passenger newPassenger3 = new Passenger("Morpheus", "Southern Swirl", "BAL");
  68. passengerList.add(newPassenger3);
  69. }
  70.  
  71. // custom method to add ships to the shipList ArrayList
  72. public static void add(String tName, int tBalcony, int tOceanView,
  73. int tSuite, int tInterior, boolean tInService) {
  74. Ship newShip = new Ship(tName, tBalcony, tOceanView, tSuite, tInterior, tInService);
  75. shipList.add(newShip);
  76. }
  77.  
  78.  
  79. public static void printShipList(String listType) {
  80. // printShipList() method prints list of ships from the
  81. // shipList ArrayList. There are three different outputs
  82. // based on the listType String parameter:
  83. // name - prints a list of ship names only
  84. // active - prints a list of ship names that are "in service"
  85. // full - prints tabbed data on all ships
  86.  
  87. if (shipList.size() < 1) {
  88. System.out.println("\nThere are no ships to print.");
  89. return;
  90. }
  91. if (listType == "name") {
  92. System.out.println("\n\nSHIP LIST - Name");
  93. for (int i = 0; i < shipList.size(); i++) {
  94. System.out.println(shipList.get(i));
  95. }
  96. } else if (listType == "active") {
  97. System.out.println("\n\nSHIP LIST - Active");
  98.  
  99. // complete this code block
  100.  
  101.  
  102. } else if (listType == "full") {
  103. System.out.println("\n\nSHIP LIST - Full");
  104. System.out.println("-----------------------------------------------");
  105. System.out.println(" Number of Rooms In");
  106. System.out.print("SHIP NAME Bal OV Ste Int Service");
  107. System.out.println("\n-----------------------------------------------");
  108. for (Ship eachShip: shipList)
  109. eachShip.printShipData();
  110.  
  111. } else
  112. System.out.println("\n\nError: List type not defined.");
  113. }
  114.  
  115. public static void printCruiseList(String listType) {
  116. if (cruiseList.size() < 1) {
  117. System.out.println("\nThere are no cruises to print.");
  118. return;
  119. }
  120. if (listType == "list") {
  121. System.out.println("\n\nCRUISE LIST");
  122. for (int i=0; i < cruiseList.size(); i++) {
  123. System.out.println(cruiseList.get(i));
  124. }
  125. } else if (listType == "details") {
  126. System.out.println("\n\nCRUISE LIST - Details");
  127. System.out.println("------------------------------------------------------------------------------------------");
  128. System.out.println(" |----------------------PORTS-----------------------|");
  129. System.out.print("CRUISE NAME SHIP NAME DEPARTURE DESTINATION RETURN");
  130. System.out.println("\n-----------------------------------------------------------------------------------------");
  131. for (Cruise eachCruise: cruiseList)
  132. eachCruise.printCruiseDetails();
  133. } else
  134. System.out.println("\n\nError: List type not defined.");
  135. }
  136.  
  137. public static void printPassengerList() {
  138. if (passengerList.size() < 1) {
  139. System.out.println("\nThere are no passengers to print.");
  140. return;
  141. }
  142. System.out.println("\n\nPASSENGER LIST");
  143. System.out.println("-----------------------------------------------------");
  144. System.out.print("PASSENGER NAME CRUISE ROOM TYPE");
  145. System.out.println("\n-----------------------------------------------------");
  146. for (Passenger eachPassenger: passengerList)
  147. eachPassenger.printPassenger();
  148. }
  149.  
  150. // display text-based menu
  151. public static void displayMenu() {
  152.  
  153. System.out.println("\n\n");
  154. System.out.println("\t\t\tLuxury Ocean Cruise Outings");
  155. System.out.println("\t\t\t\t\tSystem Menu\n");
  156. System.out.println("[1] Add Ship [A] Print Ship Names");
  157. System.out.println("[2] Edit Ship [B] Print Ship In Service List");
  158. System.out.println("[3] Add Cruise [C] Print Ship Full List");
  159. System.out.println("[4] Edit Cruise [D] Print Cruise List");
  160. System.out.println("[5] Add Passenger [E] Print Cruise Details");
  161. System.out.println("[6] Edit Passenger [F] Print Passenger List");
  162. System.out.println("[x] Exit System");
  163. System.out.println("\nEnter a menu selection: ");
  164. }
  165.  
  166. // Add a New Ship
  167. public static void addShip() {
  168.  
  169. // complete this method
  170.  
  171. }
  172.  
  173. // Edit an existing ship
  174. public static void editShip() {
  175.  
  176. // This method does not need to be completed
  177. System.out.println("The \"Edit Ship\" feature is not yet implemented.");
  178.  
  179. }
  180.  
  181. // Add a New Cruise
  182. public static void addCruise() {
  183.  
  184. // complete this method
  185.  
  186.  
  187. }
  188.  
  189. // Edit an existing cruise
  190. public static void editCruise() {
  191.  
  192. // This method does not need to be completed
  193. System.out.println("The \"Edit Cruise\" feature is not yet implemented.");
  194.  
  195. }
  196.  
  197. // Add a New Passenger
  198. public static void addPassenger() {
  199.  
  200. Scanner newPassengerInput = new Scanner(System.in);
  201. System.out.println("Enter the new passenger's name: ");
  202. String newPassengerName = newPassengerInput.nextLine();
  203.  
  204. // ensure new passenger name does not already exist
  205. for (Passenger eachPassenger: passengerList) {
  206. if (eachPassenger.getPassengerName().equalsIgnoreCase(newPassengerName)) {
  207. System.out.println("That passenger is already in the system. Exiting to menu...");
  208. return; // quits addPassenger() method processing
  209. }
  210. }
  211.  
  212. // get cruise name for passenger
  213. System.out.println("Enter cruise name: ");
  214. String newCruiseName = newPassengerInput.nextLine();
  215.  
  216. // ensure cruise exists
  217. for (Cruise eachCruise: cruiseList) {
  218. if (eachCruise.getCruiseName().equalsIgnoreCase(newCruiseName)) {
  219. // cruise does exist
  220. } else {
  221. System.out.println("That cruise does not exist in the system. Exiting to menu...");
  222. return; // quits addPassenger() method processing
  223. }
  224. }
  225.  
  226. // get room type
  227. System.out.println("Enter Room Type (BAL, OV, STE, or INT: ");
  228. String room = newPassengerInput.nextLine();
  229. // validate room type
  230. if ((room.equalsIgnoreCase("BAL")) || (room.equalsIgnoreCase("OV")) ||
  231. (room.equalsIgnoreCase("STE")) || (room.equalsIgnoreCase("INT"))) {
  232. // validation passed - add passenger
  233. Passenger newPassenger = new Passenger(newPassengerName, newCruiseName, room.toUpperCase());
  234. passengerList.add(newPassenger);
  235. } else {
  236. System.out.println("Invalid input. Exiting to menu...");
  237. return; // quits addPassenger() method processing
  238. }
  239. }
  240.  
  241. // Edit an existing passenger
  242. public static void editPassenger() {
  243.  
  244. // This method does not need to be completed
  245. System.out.println("The \"Edit Passenger\" feature is not yet implemented.");
  246.  
  247. }
  248.  
  249. // Method to check if input is a number
  250. public static boolean isANumber(String str) {
  251. for (int i = 0; i < str.length(); i++) {
  252. if (Character.isDigit(str.charAt(i)) == false)
  253. return false;
  254. }
  255. return true;
  256. }
  257.  
  258. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement