Advertisement
Guest User

bluebox

a guest
Dec 12th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.08 KB | None | 0 0
  1. package itse_2457;
  2. import java.util.Scanner;
  3. import java.util.StringTokenizer;
  4. import java.io.*;
  5. import java.io.*;
  6. public class Driver
  7. {
  8.  
  9. private int dispatchChoice;
  10. private int choice;
  11. public static void main(String[] args)
  12. {
  13. File textIn = null;
  14. Scanner scnr = null;
  15. int sentinel = 0;
  16. Rental rent = new Rental();
  17. Scanner userInput = new Scanner(System.in);
  18. //saves user choice for dispatch choice
  19. int dispatchChoice;
  20. //saves user current choice
  21. int choice;
  22. //Prints Main menu
  23. //Keeps user in the program until they choose to leave
  24. while( sentinel != -1) {
  25. printMainMenu();
  26. choice = userInput.nextInt();
  27. dispatchChoice = choice;
  28. //User main menu choice
  29. dispatchMain(choice);
  30. //user sub menu choice
  31. choice = userInput.nextInt();
  32.  
  33.  
  34. //executes user menu choice
  35. switch(dispatchChoice)
  36. {
  37.  
  38. //File Submenu
  39. case 0:
  40. //File Submenu choice
  41. switch(choice)
  42. {
  43. //Import Data
  44. case 0:
  45. //Customer Import
  46. try {
  47. //creating File instance to reference text file in Java
  48. textIn = new File("/home/burnthefern/eclipse-workspace/COSC_1336/src/itse_2457/CustomerList.txt");
  49.  
  50. //Creating Scanner instance to read File in Java
  51. scnr = new Scanner(textIn);
  52.  
  53. }
  54. catch (FileNotFoundException e)
  55. {
  56. System.out.println(e.getMessage());
  57. }
  58. catch(Exception e)
  59. {
  60. System.out.println(e.getMessage());
  61. }
  62.  
  63. String line;
  64. String delimiter = ";";
  65. String[] splitData = new String[9];
  66.  
  67. while(scnr.hasNextLine())
  68. {
  69. line = scnr.nextLine();
  70. String[] splitter = line.split(delimiter);
  71. for(int ndx = 0; ndx < splitter.length; ndx++)
  72. splitData[ndx] = splitter[ndx];
  73. Customer tempCustomer = new Customer(splitData[0], splitData[1], splitData[2], splitData[3]);
  74. rent.addCustomer(tempCustomer);
  75. }
  76. //Movie Import
  77. try {
  78. //creating File instance to reference text file in Java
  79. textIn = new File("/home/burnthefern/eclipse-workspace/COSC_1336/src/itse_2457/MovieList.txt");
  80.  
  81. //Creating Scanner instance to read File in Java
  82. scnr = new Scanner(textIn);
  83.  
  84. }
  85. catch (FileNotFoundException e)
  86. {
  87. System.out.println(e.getMessage());
  88. }
  89. catch(Exception e)
  90. {
  91. System.out.println(e.getMessage());
  92. }
  93.  
  94.  
  95. while(scnr.hasNextLine())
  96. {
  97.  
  98. line = scnr.nextLine();
  99. String[] splitDataMovie = new String[5];
  100. String[] splitter = line.split(delimiter);
  101. for(int ndx = 0; ndx < splitter.length; ndx++)
  102. splitDataMovie[ndx] = splitter[ndx];
  103. int[] movieData = new int[3];
  104. movieData[0] = Integer.valueOf(splitDataMovie[0]);
  105. movieData[1] = Integer.valueOf(splitDataMovie[3]);
  106. movieData[2] = Integer.valueOf(splitDataMovie[4]);
  107. Movie tempMovie = new Movie(movieData[0], splitDataMovie[1], splitDataMovie[2], movieData[1], movieData[2]);
  108. rent.addMovie(tempMovie);
  109. }
  110. break;
  111. //Data Export
  112. case 1:
  113.  
  114.  
  115. break;
  116. //Return to previous Menu
  117. case 2:
  118. break;
  119. }
  120.  
  121. break;
  122. case 1://Edit Submenu
  123. switch(choice)
  124. {
  125. //Add Customer
  126. case 0:
  127. String[] newCustomerInfo = new String[9];
  128. System.out.println("Please Input customer ID number: ");
  129. System.out.print(">tkn: ");
  130. newCustomerInfo[0] = userInput.next();
  131. System.out.println("\nPlease Input Customer Name: ");
  132. System.out.print(">: ");
  133. newCustomerInfo[1] = userInput.next();
  134. System.out.println("\nPlease input customer address");
  135. System.out.print(">: ");
  136. newCustomerInfo[2] = userInput.next();
  137. System.out.println("\nPlease input customer phone number");
  138. System.out.print(">: ");
  139. newCustomerInfo[3] = userInput.next();
  140. if( newCustomerInfo[0].length() > 0)
  141. {
  142. Customer tempCustomer = new Customer(newCustomerInfo[0], newCustomerInfo[1], newCustomerInfo[2], newCustomerInfo[3]);
  143. rent.addCustomer(tempCustomer);
  144. }
  145. else System.out.println("Customer ID must be provided! Customer was not added.");
  146. //
  147. // System.out.print("Please input customer ");
  148. // newCustomerInfo[4] = userInput.nextLine();
  149. // System.out.print();
  150. // newCustomerInfo[5] = userInput.nextLine();
  151. // System.out.print();
  152. // newCustomerInfo[6] = userInput.nextLine();
  153. // System.out.print();
  154. // newCustomerInfo[7] = userInput.nextLine();
  155. // System.out.print();
  156. // newCustomerInfo[8] = userInput.nextLine();
  157.  
  158. break;
  159. //Add Movie
  160. case 1:
  161. int[] movieData = new int[3];
  162. String[] movieDataS = new String[2];
  163. System.out.println("Please enter Movie ID: ");
  164. System.out.print(">: ");
  165. movieData[0] = userInput.nextInt();
  166. System.out.println("\nPlease enter Movie Title:");
  167. System.out.print(">: ");
  168. movieDataS[0] = userInput.next(); //might not read entire title
  169. System.out.println("\nPlease enter Movie Genre: ");
  170. System.out.print(">: ");
  171. movieDataS[1] = userInput.next();
  172. System.out.println("\nPlease enter number of Copies Available: ");
  173. System.out.print(">: ");
  174. movieData[1] = userInput.nextInt();
  175. System.out.println("\nPlease enter number of copies currently checked out: ");
  176. System.out.print(">: ");
  177. movieData[2] = userInput.nextInt();
  178.  
  179. if(movieData[0] > 0 && movieDataS[0].length() > 0 && movieData[1] > 0)
  180. {
  181. Movie tempMovie = new Movie(movieData[0], movieDataS[0], movieDataS[1], movieData[1], movieData[2]);
  182. rent.addMovie(tempMovie);
  183. }
  184. else System.out.println("Missing Information! All movies require the following: "
  185. + "\n1) Movie ID \n2) Movie Title \n3)Number of copies available");
  186. break;
  187. //Update Customer
  188. case 2:
  189. String searchID = new String();
  190. System.out.print("Please enter Customer ID: ");
  191. searchID = userInput.next();
  192. int custNdx;
  193. int choose;
  194. for(int ndx = 0; ndx < rent.customers.length; ndx++)
  195. {
  196. Customer tempCust = rent.customers[ndx];
  197. String checkID = tempCust.getCustID();
  198. boolean eqResult = checkID.equals(searchID);
  199. if(eqResult)
  200. custNdx = ndx;
  201. }
  202. System.out.println("What would you like to update?");
  203. printUpdateCustomerMenu();
  204. choose = userInput.nextInt();
  205. switch(choose)
  206. {
  207. case 0:
  208. break;
  209. case 1:
  210. break;
  211. case 2:
  212. break;
  213. case 3:
  214. break;
  215. }
  216.  
  217. break;
  218. //Update Movie
  219. case 3:
  220. break;
  221. //Delete Customer
  222. case 4:
  223. break;
  224. //Delete Movie
  225. case 5:
  226. break;
  227. //Return to Previous Menu
  228. case 6:
  229. break;
  230. }
  231.  
  232. break;
  233. //View Submenu
  234. case 2:
  235. switch(choice)
  236. {
  237. case 0:
  238. break;
  239. case 1:
  240. break;
  241. case 2:
  242. break;
  243. case 3:
  244. break;
  245. case 4:
  246. break;
  247. case 5:
  248. break;
  249.  
  250. }
  251.  
  252. break;
  253. //Sort Submenu
  254. case 3:
  255. switch(choice)
  256. {
  257. case 0:
  258. break;
  259. case 1:
  260. break;
  261. case 2:
  262. break;
  263. case 3:
  264. break;
  265. case 4:
  266. break;
  267. case 5:
  268. break;
  269. }
  270. break;
  271. //RentReturn submenu
  272. case 4:
  273. switch(choice)
  274. {
  275. case 0:
  276. break;
  277. case 1:
  278. break;
  279. case 2:
  280. break;
  281. case 3:
  282. break;
  283. case 4:
  284. break;
  285. case 5:
  286. break;
  287. }
  288. break;
  289. //Exit Rent App
  290. case 5:
  291. sentinel = -1;
  292. break;
  293. }
  294.  
  295. }//end of while loop
  296. }//end of PSVM
  297.  
  298.  
  299.  
  300. public static void printMainMenu()
  301. {
  302. System.out.println("\n Menu");
  303. System.out.println("========");
  304. System.out.println("0: File:");
  305. System.out.println("1: Edit:");
  306. System.out.println("2: View:");
  307. System.out.println("3: Sort:");
  308. System.out.println("4: Rent or Return:");
  309. System.out.println("5: Exit Rental Application:");
  310. System.out.print("\nEnter your Choice: ");
  311. }
  312. public static void printFileSubMenu()
  313. {
  314. System.out.println("\n Sub Menu");
  315. System.out.println("=======");
  316. System.out.println("0: Import Data");
  317. System.out.println("1: Export Data");
  318. System.out.println("2: Return to Previous Menu");
  319. System.out.print("\nEnter your choice: ");
  320. }
  321.  
  322. public static void printEditSubMenu()
  323. {
  324. System.out.println("\n Sub Menu");
  325. System.out.println("=======");
  326. System.out.println("0: Add CUstomer");
  327. System.out.println("1: Add Movie");
  328. System.out.println("2: Update Customer");
  329. System.out.println("3: Update Movie");
  330. System.out.println("4: Delete Customer");
  331. System.out.println("5: Delete Movie");
  332. System.out.println("6: Return to Previous Menu");
  333. System.out.print("\nEnter your choice: ");
  334. }
  335.  
  336. public static void printViewSubMenu()
  337. {
  338. System.out.println("\n Sub Menu");
  339. System.out.println("=======");
  340. System.out.println("0: All Customers");
  341. System.out.println("1: Specific Customer");
  342. System.out.println("2: All Movies");
  343. System.out.println("3: Specific Movie");
  344. System.out.println("4: Specific Genre");
  345. System.out.println("5: Return to Previous Menu");
  346. System.out.print("\nEnter your choice: ");
  347. }
  348.  
  349. public static void printSortSubMenu()
  350. {
  351. System.out.println("\n Sub Menu");
  352. System.out.println("=======");
  353. System.out.println("0: Sort Customer by Name");
  354. System.out.println("1: Sort Customer by CustID");
  355. System.out.println("2: Sort Movie by Title");
  356. System.out.println("3: Sort Movie by Genre");
  357. System.out.print("\nEnter your choice: ");
  358. }
  359.  
  360. public static void printRentReturnSubMenu()
  361. {
  362. System.out.println("\n Sub Menu");
  363. System.out.println("======");
  364. System.out.println("0: Return a Movie");
  365. System.out.println("1: Rent a Movie");
  366. System.out.println("2: Return to Previous Menu");
  367. System.out.print("\nEnter your choice: ");
  368. }
  369.  
  370. public static void printUpdateCustomerMenu()
  371. {
  372. System.out.println("\n Customer Updater");
  373. System.out.println("=======");
  374. System.out.println("0: Update Customer ID");
  375. System.out.println("1: Update Customer Name");
  376. System.out.println("2: Update Customer Address");
  377. System.out.println("3: Update Customer Phone Number");
  378. System.out.println("4: Return to Previous Menu");
  379. System.out.print("\nEnter your choice: ");
  380. }
  381.  
  382. //Determines user choice and navigates to appropriate menu
  383. //based on user choice
  384. public static void dispatchMain(int choice)
  385. {
  386. switch(choice)
  387. {
  388. case 0:
  389. printFileSubMenu();
  390. break;
  391. case 1:
  392. printEditSubMenu();
  393. break;
  394. case 2:
  395. printViewSubMenu();
  396. break;
  397. case 3:
  398. printSortSubMenu();
  399. break;
  400. case 4:
  401. printRentReturnSubMenu();
  402. break;
  403. case 5:
  404. System.out.println("Goodbye!");
  405. break;
  406. }
  407. }
  408.  
  409. }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement