Advertisement
Guest User

new stuff

a guest
Sep 26th, 2016
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.98 KB | None | 0 0
  1.  
  2. // Humza Hnesh
  3. // CS0401
  4. // Tuesday/Thursday 9:30-10:45 AM
  5.  
  6. /* My program is not very robust and does not work 100% as the assignment formatted.
  7. I had many issues with running back through my loops when I inputted a value that was
  8. incorrect. Thus, my program is filled with many work arounds rather than addressing the
  9. real problem (unfortunately). When handling exceptions, I often exited or re-ran the loops
  10. entirely...
  11.  
  12. */
  13.  
  14.  
  15. import java.util.Scanner;
  16.  
  17. public class Assignment1CS0401 {
  18. public static void main(String[] args) {
  19.  
  20. Scanner inScan=new Scanner(System.in);
  21. Scanner inScan2=new Scanner(System.in);
  22. Scanner inScan3=new Scanner(System.in);
  23. Scanner inScan4=new Scanner(System.in);
  24. Scanner inScan5=new Scanner(System.in);
  25. Scanner inScan6=new Scanner(System.in);
  26. Scanner inScan7=new Scanner(System.in);
  27. Scanner inScan8=new Scanner(System.in);
  28. Scanner inScan9=new Scanner(System.in);
  29. Scanner inScan10=new Scanner(System.in);
  30. Scanner inScan11=new Scanner(System.in);
  31. Scanner inScan12=new Scanner(System.in);
  32. boolean registerloop = false;
  33. // I created many Scanners because I wanted to store the values I scanned progressively
  34. // and I feared that I would erase values I needed
  35.  
  36. String passwordIn = "a";
  37.  
  38. int customer = 1;
  39.  
  40. int update;
  41. int update2=0;
  42. int update3=0;
  43. int update4=0;
  44. int update5=0;
  45. int order1=0;
  46. int order2=0;
  47. int order3=0;
  48. int order4=0;
  49. int total_value = 0;
  50. int total_value2 = 0;
  51. int total_value3 = 0;
  52. int butterval = 0;
  53. int butterval2 = 0;
  54. int remainder = 0;
  55. int difference = 0;
  56. int bag_count = 0;
  57. int totally = 0;
  58. int totallydiscountprice = 0;
  59. int totallydiscount = 0;
  60. int firstNum = 0;
  61.  
  62. //initialized my variables outside so didn't have to worry about scope
  63.  
  64. String firstString = " ";
  65.  
  66.  
  67. do
  68. {
  69. System.out.println("Welcome to Dumbledore's Delicious Delicacies!");
  70. System.out.println("Is there a customer in line? ( 1 = yes, 2 = no) >");
  71. customer = inScan.nextInt();
  72. if (customer==2){
  73. System.out.println("Thank you!");
  74. }
  75. else {
  76. System.out.println("What is the password? ");
  77. passwordIn = inScan2.nextLine();
  78.  
  79. String password1 = "Dumbledore's Army";
  80.  
  81. int attempts = 1;
  82.  
  83. do
  84. {
  85. if (password1.equals(passwordIn))
  86. {
  87. System.out.println("Welcome Dumbledore's Army member!");
  88. System.out.println("You will get special discounts at DDD!! ");
  89. System.out.println(" Discount on bags of Cauldron Cakes");
  90. System.out.println(" Discount on Chocolate Frogs");
  91. System.out.println(" Small or Large Butterbeer - same price");
  92.  
  93. System.out.println(" ");
  94. System.out.println("Here is our price list:");
  95. System.out.println(" Cauldron Cakes (each) 10 Knuts");
  96. System.out.println(" Cauldron Cakes (bag of 6) 50 Knuts");
  97. System.out.println(" Chocolate Frogs (each) 15 Knuts");
  98. System.out.println(" Butterbeer (small) 50 Knuts ");
  99. System.out.println(" Butterbeer (large) 50 Knuts ");
  100. System.out.println(" ");
  101. // used tabs to format output
  102.  
  103.  
  104.  
  105. do{
  106. System.out.println("1) Update Cauldron Cakes Order");
  107. System.out.println("2) Update Chocolate Frogs Order");
  108. System.out.println("3) Update Butterbeer Order");
  109. System.out.println("4) Check Out");
  110. update = inScan3.nextInt();
  111.  
  112. if (update == 1 )
  113. {
  114. System.out.println("Here is your current order");
  115. System.out.println(order1);
  116. System.out.println("How many Cauldron Cakes would you like for: ");
  117. System.out.println(" 10 Knuts per cake");
  118. System.out.println(" 50 Knuts per bag of 6");
  119. System.out.println("(Please indicate only the total amount of cakes you would like to buy): ");
  120. order1 = order1 + inScan4.nextInt();
  121. remainder = order1 % 6;
  122. difference = order1 - remainder;
  123. bag_count = difference/6;
  124. total_value = (remainder * 10 ) + (bag_count * 50);
  125.  
  126.  
  127. }
  128.  
  129. else if (update == 2)
  130. {
  131. System.out.println("Here is your current order");
  132. System.out.println(order2);
  133. System.out.println("How many chocolate frogs would you like for 15 Knuts each?: ");
  134. order2 = order2 + inScan5.nextInt();
  135.  
  136. total_value2 = order2 * 15;
  137.  
  138.  
  139.  
  140. }
  141.  
  142. else if (update == 3)
  143. {
  144. System.out.println("Here is your current order");
  145. System.out.println(order3 + order4);
  146. System.out.println("How many small Butterbeers would you like for 50 Knuts each?: ");
  147. order3 = order3 + inScan6.nextInt();
  148. butterval = order3 * 50;
  149.  
  150. System.out.println("How many large Butterbeers would you like for 50 Knuts each?: ");
  151. order4 = order4 + inScan7.nextInt();
  152. butterval2 = order4 * 50;
  153.  
  154. total_value3= butterval + butterval2;
  155.  
  156. }
  157.  
  158. }
  159. while ( update !=4);
  160.  
  161. totally = total_value+total_value2+total_value3;
  162. totallydiscount = totally/10;
  163. totallydiscountprice= totally - (totallydiscount);
  164.  
  165. System.out.println("Here is your subtotal");
  166. System.out.println(" " + bag_count + " bags of Cauldron cakes at 50 Knuts ea. " +(bag_count * 50 ));
  167. System.out.println(" " + remainder + " Cauldron cakes at 10 Knuts ea.: " + (remainder *10));
  168. System.out.println(" " + order2 + " Chocolate Frogs at 15 Knuts ea.: " + total_value2 );
  169. System.out.println(" " + order3 + " Small Butterbeers at 50 Knuts ea.: " + butterval);
  170. System.out.println(" " + order4 + " Large Butterbeers at 50 Knuts ea.: " + butterval2);
  171. System.out.println(" ");
  172. System.out.println(" " + " Total: " + totally);
  173. System.out.println(" " + " Bonus Discount of 10%!: " + totallydiscount);
  174. System.out.println(" " + " New Total: " + totallydiscountprice);
  175. System.out.println(" ");
  176.  
  177. // used tabs to format output
  178.  
  179.  
  180.  
  181. System.out.println("Please enter your payment amount in the following format: ");
  182. System.out.println(" <amount><space><currency>");
  183. System.out.println(" Where <amount> = an integer");
  184. System.out.println(" Where <currency> = {Knuts, Sickles, Galleons}");
  185. System.out.println(" > ");
  186.  
  187. String userInput = inScan12.nextLine();
  188. int positionOfSpace = userInput.indexOf(" "); //I used this to find the position of the space in order to know where to parse for the values before and after
  189.  
  190. String num = userInput.substring(0, positionOfSpace); //Grabs the "number" that is currently a string
  191. int payment = Integer.parseInt(num); // Because the value is initially a string, used this to make the number into int
  192. String txt = userInput.substring(positionOfSpace + 1); //Grab the currency type
  193. // this way I handle users that want to be difficult and type capital letters vs lowercase letters
  194. txt = txt.toLowerCase();
  195.  
  196.  
  197.  
  198. do {
  199.  
  200.  
  201.  
  202. if (txt.equals("galleons") && payment>=0) // handles if they enter negative numbers
  203. {
  204. int check = payment * 493;
  205.  
  206. System.out.println("Thank you!");
  207. System.out.println("Here is your change: ");
  208. System.out.println("");
  209. int change = check - totallydiscountprice;
  210. if (change<0)
  211. {
  212. System.out.println("You don't have enough money! Get out of here");
  213.  
  214. }
  215. else
  216. {
  217. int changeSickles = change / 29;
  218. int changeKnuts = change % 29;
  219. System.out.println(" " + changeSickles + " Sickles");
  220. System.out.println(" " + changeKnuts + " Knuts");
  221. registerloop = true;
  222. }
  223.  
  224. }
  225. else if (txt.equals("sickles") && payment>=0)
  226. {
  227. int check = payment * 29;
  228.  
  229. System.out.println("Thank you!");
  230. System.out.println("Here is your change: ");
  231. System.out.println("");
  232. int change = check - totallydiscountprice;
  233. if (change<0)
  234. {
  235. System.out.println("You don't have enough money! Get out of here");
  236.  
  237. }
  238. else
  239. {
  240. int changeSickles = change / 29;
  241. int changeKnuts = change % 29;
  242. System.out.println(" " + changeSickles + " Sickles");
  243. System.out.println(" " + changeKnuts + " Knuts");
  244. registerloop = true;
  245. }
  246. }
  247. else if (txt.equals("knuts") && payment>=0)
  248. {
  249. int check = payment;
  250. System.out.println("Thank you!");
  251. System.out.println("Here is your change: ");
  252. System.out.println("");
  253. int change = check - totallydiscountprice;
  254. if (change<0)
  255. {
  256. System.out.println("You don't have enough money! Get out of here");
  257.  
  258. }
  259. else
  260. {
  261. int changeSickles = change / 29;
  262. int changeKnuts = change % 29;
  263. System.out.println(" " + changeSickles + " Sickles");
  264. System.out.println(" " + changeKnuts + " Knuts");
  265. registerloop = true;
  266. }
  267. }
  268.  
  269.  
  270.  
  271. } while (!(registerloop));
  272.  
  273.  
  274. System.out.println("Thank you for shopping at DDD!");
  275. System.out.println(" ");
  276.  
  277.  
  278.  
  279.  
  280.  
  281. attempts++;
  282. }
  283. else if (attempts < 2 && !password1.equals(passwordIn))
  284. {
  285. System.out.println("Sorry, but that is not right. We will give you one more chance: ");
  286. passwordIn = inScan2.nextLine();
  287. attempts++;
  288. }
  289. else if (attempts == 2)
  290. {
  291.  
  292. System.out.println("Please enjoy our items ");
  293. System.out.println(" ");
  294. System.out.println("Here is our price list:");
  295. System.out.println(" Cauldron Cakes (each) 10 Knuts");
  296. System.out.println(" Cauldron Cakes (bag of 6) 55 Knuts");
  297. System.out.println(" Chocolate Frogs (each) 20 Knuts");
  298. System.out.println(" Butterbeer (small) 50 Knuts ");
  299. System.out.println(" Butterbeer (large) 75 Knuts ");
  300. System.out.println(" ");
  301.  
  302.  
  303.  
  304. do{
  305. System.out.println("1) Update Cauldron Cakes Order");
  306. System.out.println("2) Update Chocolate Frogs Order");
  307. System.out.println("3) Update Butterbeer Order");
  308. System.out.println("4) Check Out");
  309. update = inScan3.nextInt();
  310.  
  311. if (update == 1 )
  312. {
  313. System.out.println("Here is your current order");
  314. System.out.println(order1);
  315. System.out.println("How many Cauldron Cakes would you like for: ");
  316. System.out.println(" 10 Knuts per cake");
  317. System.out.println(" 55 Knuts per bag of 6");
  318. System.out.println("(Please indicate only the total amount of cakes you would like to buy): ");
  319. order1 = order1 + inScan4.nextInt();
  320. remainder = order1 % 6;
  321. difference = order1 - remainder;
  322. bag_count = difference/6;
  323. total_value = (remainder * 10 ) + (bag_count * 55);
  324. System.out.println(total_value + " Knuts"); // This price displays the total amount from previous entries as well as the current entry, not the price of every additional entry separately
  325.  
  326. }
  327.  
  328. else if (update == 2)
  329. {
  330. System.out.println("Here is your current order");
  331. System.out.println(order2);
  332. System.out.println("How many chocolate frogs would you like for 20 Knuts each?: ");
  333. order2 = order2 + inScan5.nextInt();
  334.  
  335. total_value2 = order2 * 20;
  336. System.out.println(total_value2 + " Knuts");
  337.  
  338.  
  339. }
  340.  
  341. else if (update == 3)
  342. {
  343. System.out.println("Here is your current order");
  344. System.out.println(order3 + order4);
  345. System.out.println("How many small Butterbeers would you like for 50 Knuts each?: ");
  346. order3 = order3 + inScan6.nextInt();
  347. butterval = order3 * 50;
  348.  
  349. System.out.println("How many large Butterbeers would you like for 75 Knuts each?: ");
  350. order4 = order4 + inScan7.nextInt();
  351. butterval2 = order4 * 75;
  352.  
  353. total_value3= butterval + butterval2;
  354. System.out.println(total_value3 + " Knuts");
  355. }
  356.  
  357. }
  358. while ( update !=4);
  359.  
  360. totally = total_value+total_value2+total_value3;
  361.  
  362. System.out.println("Here is your subtotal");
  363. System.out.println(" " + bag_count + " bags of Cauldron cakes at 55 Knuts ea. " +(bag_count * 55 ));
  364. System.out.println(" " + remainder + " Cauldron cakes at 10 Knuts ea.: " + (remainder *10));
  365. System.out.println(" " + order2 + " Chocolate Frogs at 20 Knuts ea.: " + total_value2 );
  366. System.out.println(" " + order3 + " Small Butterbeers at 50 Knuts ea.: " + butterval);
  367. System.out.println(" " + order4 + " Large Butterbeers at 75 Knuts ea.: " + butterval2);
  368. System.out.println(" " + " Total: " + totally);
  369. System.out.println(" ");
  370. //tabs and spaces used to format
  371.  
  372.  
  373. System.out.println("Please enter your payment amount in the following format: ");
  374. System.out.println(" <amount><space><currency>");
  375. System.out.println(" Where <amount> = an integer");
  376. System.out.println(" Where <currency> = {Knuts, Sickles, Galleons}");
  377. System.out.println(" > ");
  378. //
  379. String userInput = inScan12.nextLine();
  380. int positionOfSpace = userInput.indexOf(" "); //I used this to find the position of the space in order to know where to parse for the values before and after
  381.  
  382. String num = userInput.substring(0, positionOfSpace); //Grabs the "number" that is currently a string
  383. int payment = Integer.parseInt(num); // Because the value is initially a string, used this to make the number into int
  384. String txt = userInput.substring(positionOfSpace + 1); //Grab the currency type
  385. // this way I handle users that want to be difficult and type capital letters vs lowercase letters
  386. txt = txt.toLowerCase();
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393. do {
  394.  
  395.  
  396.  
  397. if (txt.equals("galleons") && payment>=0) // handles if they enter negative numbers
  398. {
  399. int check = payment * 493;
  400.  
  401. System.out.println("Thank you!");
  402. System.out.println("Here is your change: ");
  403. System.out.println("");
  404. int change = check - totally;
  405. if (change<0)
  406. {
  407. System.out.println("You don't have enough money! Get out of here");
  408.  
  409. }
  410. else
  411. {
  412. int changeSickles = change / 29;
  413. int changeKnuts = change % 29;
  414. System.out.println(" " + changeSickles + " Sickles");
  415. System.out.println(" " + changeKnuts + " Knuts");
  416. registerloop = true;
  417. }
  418.  
  419. }
  420. else if (txt.equals("sickles") && payment>=0)
  421. {
  422. int check = payment * 29;
  423.  
  424. System.out.println("Thank you!");
  425. System.out.println("Here is your change: ");
  426. System.out.println("");
  427. int change = check - totally;
  428. if (change<0)
  429. {
  430. System.out.println("You don't have enough money! Get out of here");
  431.  
  432. }
  433. else
  434. {
  435. int changeSickles = change / 29;
  436. int changeKnuts = change % 29;
  437. System.out.println(" " + changeSickles + " Sickles");
  438. System.out.println(" " + changeKnuts + " Knuts");
  439. registerloop = true;
  440. }
  441. }
  442. else if (txt.equals("knuts") && payment>=0)
  443. {
  444. int check = payment;
  445. System.out.println("Thank you!");
  446. System.out.println("Here is your change: ");
  447. System.out.println("");
  448. int change = check - totally;
  449. if (change<0)
  450. {
  451. System.out.println("You don't have enough money! Get out of here");
  452.  
  453. }
  454. else
  455. {
  456. int changeSickles = change / 29;
  457. int changeKnuts = change % 29;
  458. System.out.println(" " + changeSickles + " Sickles");
  459. System.out.println(" " + changeKnuts + " Knuts");
  460. registerloop = true;
  461. }
  462. }
  463.  
  464.  
  465.  
  466. } while (!(registerloop));
  467.  
  468.  
  469. System.out.println("Thank you for shopping at DDD!");
  470. System.out.println(" ");
  471.  
  472.  
  473. attempts++;
  474. }
  475.  
  476. }
  477. while (attempts < 3 && !password1.equals(passwordIn));
  478. }
  479. }
  480. while (customer==1 && customer!=2);
  481.  
  482.  
  483.  
  484. }
  485. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement