Advertisement
202revenge

Java nightmare(Assignment 5)

Oct 28th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.90 KB | None | 0 0
  1. ===========================================================================================
  2. PizzaDriver.java
  3. ===========================================================================================
  4. /*
  5. *File name: PizzaDriver.java
  6. *
  7. *Programmer: Derek Townsend
  8. *ULID: djtown1
  9. *
  10. *Date: Oct 27, 2017
  11. *
  12. *Class: IT 168
  13. *Lecture Section: 004
  14. *Lecture Instructor:Dr Xing Fang
  15. *Lab Section: 005
  16. *Lab Instructor: Simran Kaur
  17. */
  18. package edu.ilstu;
  19. import java.util.Scanner;
  20. /*
  21. *<insert description>
  22. *
  23. * @author Derek
  24. *
  25. */
  26. public class PizzaDriver
  27. {
  28.  
  29. public static void main(String[] args)
  30. {
  31. boolean phoneFlag=true, addressFlag=true;
  32. String userAddress="" ,fullName="" ,phoneNumber="" ,address="" ,deliveryOrder="" , confirmOrder="";
  33. Scanner keyboard =new Scanner(System.in);
  34. Customer customer1=new Customer();
  35. Store store1=new Store();
  36. Order order1=new Order();
  37. PizzaBuilder pizza1= new PizzaBuilder();
  38.  
  39.  
  40.  
  41. System.out.print("Welcome to ILSTU pizza store, lets cook your Pizza \n" +
  42. "First: is this for a pickup or delivery? type 1 for pickup, 2 for delivery\n Answer: ");
  43.  
  44. deliveryOrder=keyboard.next();
  45. order1.setOrderType(deliveryOrder);
  46.  
  47. if(order1.getOrderType().equals("pickup order")){
  48. System.out.print("Pick a location that is close to you by typing 1, 2 or 3:\n" +
  49. "\t1-207 W north st, Normal IL\n" +
  50. "\t2-305 S main st, Normal IL\n" +
  51. "\t3-208 landmark, Bloomington IL\n" +
  52. "Answer: ");
  53. address=keyboard.next();
  54.  
  55. while(addressFlag==true) {
  56. if (address.equals("1")||address.equals("2")||address.equals("3")) {
  57. addressFlag=false;
  58. }else {
  59. addressFlag=true;
  60. System.out.println("Try again, not a valid location");
  61. address=keyboard.next();
  62. }
  63. store1.pickingLocation(address);
  64. }
  65. }else if(order1.getOrderType().equals("delivery")){
  66.  
  67. System.out.print("\nPlease enter your full name: ");
  68. keyboard.nextLine();
  69. fullName=keyboard.nextLine();
  70. System.out.print("Please enter the address: ");
  71. userAddress=keyboard.nextLine();
  72.  
  73. System.out.print("\nPlease provide the phone number starting with the area code: ");
  74.  
  75. phoneNumber=keyboard.next();
  76.  
  77. while(phoneFlag==true) {
  78. if (phoneNumber.length()==10) {
  79. phoneFlag=false;
  80. }else if((phoneNumber.length()<10)) {
  81. phoneFlag=true;
  82. System.out.println("Too short, try again");
  83. phoneNumber=keyboard.next();
  84. }else if(phoneNumber.length()>10) {
  85. phoneFlag=true;
  86. System.out.println("Too long, try again");
  87. phoneNumber=keyboard.next();
  88. }
  89.  
  90. }
  91.  
  92.  
  93.  
  94. }
  95. customer1.readInformation(fullName, userAddress, phoneNumber);
  96.  
  97. System.out.print(pizza1.chooseSauce());
  98. pizza1.setSauce(keyboard.next());
  99.  
  100. System.out.print("\nTopping list: \n" +
  101. "\t1-onion\n" +
  102. "\t2-olives\n" +
  103. "\t3-tomato\n" +
  104. "\t4-mushrooms\n" +
  105. "\t5-green peppers\n" +
  106. "\t6-Pepperoni\n"
  107. );
  108.  
  109. pizza1.chooseTopping();
  110. boolean flag2=true;
  111. int counter=-1;
  112. while(flag2==true){
  113. counter++;
  114. System.out.print("Do you want to add another? type yes or no\n");
  115. String anotherTopping=keyboard.next();
  116. if(anotherTopping.equalsIgnoreCase("yes")) {
  117. pizza1.chooseTopping();
  118.  
  119. }else if(anotherTopping.equalsIgnoreCase("no")){
  120. flag2=false;
  121. }
  122.  
  123.  
  124. }
  125. pizza1.setNumOfToppings(counter);
  126.  
  127.  
  128. System.out.println("do you want extra cheese, its Free :)? Type Y for Yes or N for No ");
  129. pizza1.setCheese(keyboard.next());
  130.  
  131.  
  132. if(order1.getOrderType().equals("pickup order")){
  133. System.out.println("Order Summary: \n" +
  134. "______________ \n" +
  135. "This is a "+order1.getOrderType() +
  136. ", location of the store to pickup from is "+
  137. store1.getLocation()+"\n" +
  138. " The pizza will have "+
  139. pizza1.getSauce() +
  140. " sauce, with "+
  141. pizza1.getCheese()+
  142. ", and "+pizza1.determineTopping() +" toppings\n");
  143. order1.summary(pizza1.getNumOfToppings());
  144.  
  145. }else if(order1.getOrderType().equals("delivery")){
  146. System.out.println("Order Summary: \n" +
  147. "______________ \n" +
  148. "This is a "+order1.getOrderType() +
  149. " order, deliver to "+
  150. customer1.getFullName()+"\nAddress: " +
  151. customer1.getAddress()+
  152. "\nPhone number to call in case we got lost \n"+
  153. customer1.getPhoneNumber()+
  154. "\n The pizza will have "+
  155. pizza1.getSauce() +
  156. " sauce, with "+
  157. pizza1.getCheese()+
  158. ", and "+pizza1.determineTopping() +" toppings\n");
  159. order1.summary(pizza1.getNumOfToppings());
  160.  
  161. }
  162.  
  163. System.out.println("Do you want to place the order? type y for Yes and n for No");
  164. confirmOrder=keyboard.next();
  165. boolean cheeseflag=true;
  166. while(cheeseflag==true) {
  167. if(!confirmOrder.equalsIgnoreCase("Y")&&!confirmOrder.equalsIgnoreCase("N")) {
  168. System.out.println("This is not a valid response please enter a new one");
  169. confirmOrder=keyboard.next();
  170. cheeseflag=true;
  171. }else if(confirmOrder.equalsIgnoreCase("Y")){
  172. System.out.println("Your pizza will be ready in 30 min, Thanks for doing business with us.");
  173. cheeseflag=false;
  174. }else if(confirmOrder.equalsIgnoreCase("N")){
  175. System.out.println("Thanks for wasting our time. Please don't visit us again.");
  176. cheeseflag=false;
  177. }
  178. }
  179. keyboard.close();
  180. }
  181.  
  182.  
  183.  
  184. }
  185. ===========================================================================================
  186. PizzaDriver.java
  187. ===========================================================================================
  188. /*
  189. *File name: Order.java
  190. *
  191. *Programmer: Derek Townsend
  192. *ULID: djtown1
  193. *
  194. *Date: Oct 26, 2017
  195. *
  196. *Class: IT 168
  197. *Lecture Section: 004
  198. *Lecture Instructor:Dr Xing Fang
  199. *Lab Section: 005
  200. *Lab Instructor: Simran Kaur
  201. */
  202. package edu.ilstu;
  203. import java.util.Scanner;
  204.  
  205. /*
  206. *<insert description>
  207. *
  208. * @author Derek
  209. *
  210. */
  211. public class Order
  212. {
  213. private String orderType;
  214. public final int TOPPING_PRICE=5;
  215. public final double SALES_TAX=1.075;
  216. public final double DELIVERY_CHARGE=.20;
  217. Scanner keyboard =new Scanner(System.in);
  218. public void setOrderType(String deliveryOrPickup) {
  219. boolean orderFlag=true;
  220. while(orderFlag==true) {
  221. if (deliveryOrPickup.equals("1")||deliveryOrPickup.equals("2")) {
  222. orderFlag=false;
  223.  
  224. }else {
  225. orderFlag=true;
  226. System.out.println("Wrong choice, please type 1 for pickup and 2 for delivery");
  227. deliveryOrPickup=keyboard.next();
  228. }
  229.  
  230. }
  231.  
  232. if (deliveryOrPickup.equals("1")) {
  233. orderType="pickup order";
  234. }else if(deliveryOrPickup.equals("2")) {
  235. orderType="delivery";
  236. }
  237.  
  238. }
  239.  
  240. public String getOrderType() {
  241. return orderType;
  242. }
  243.  
  244. public void summary(int numOfToppings) {
  245. double subtotal,total,deliveryCharge;
  246.  
  247. if (orderType.equals("pickup order")) {
  248.  
  249.  
  250. subtotal=TOPPING_PRICE+(numOfToppings);
  251. total=subtotal*SALES_TAX;
  252. System.out.printf("The subtotal is:\t\t$%,.2f \n",subtotal);
  253. System.out.printf("The total cost is:\t\t$%,.2f \n",total);
  254.  
  255. }else if(orderType.equals("delivery")) {
  256. subtotal=TOPPING_PRICE+(numOfToppings);
  257. deliveryCharge=subtotal*DELIVERY_CHARGE;
  258. total=(subtotal+deliveryCharge)*SALES_TAX;
  259. System.out.printf("The subtotal is:\t\t$%,.2f \n",subtotal);
  260. System.out.printf("The delivery charge is:\t\t$%,.2f \n",deliveryCharge);
  261. System.out.printf("The total cost is:\t\t$%,.2f \n",total);
  262. }
  263. }
  264.  
  265.  
  266.  
  267.  
  268. }
  269.  
  270. ===========================================================================================
  271. PizzaDriver.java
  272. ===========================================================================================
  273. /*
  274. *File name: PizzaBuilder.java
  275. *
  276. *Programmer: Derek Townsend
  277. *ULID: djtown1
  278. *
  279. *Date: Oct 26, 2017
  280. *
  281. *Class: IT 168
  282. *Lecture Section: 004
  283. *Lecture Instructor:Dr Xing Fang
  284. *Lab Section: 005
  285. *Lab Instructor: Simran Kaur
  286. */
  287. package edu.ilstu;
  288. import java.util.Scanner;
  289. /*
  290. *<insert description>
  291. *
  292. * @author Derek
  293. *
  294. */
  295. public class PizzaBuilder
  296. {
  297.  
  298. private String sauce,cheese,currentToppings="";
  299. private int numOfToppings;
  300. Scanner keyboard =new Scanner(System.in);
  301. public String chooseSauce() {
  302.  
  303. return "\nSecond, lets build your pizza\r\n" +
  304. "Pick a source by typing the sauce:\n" +
  305. "List of sauces: "+
  306. "\n\t\tSalsa"+
  307. "\n\t\tBBQ "+
  308. "\n\t\tTapenade"+
  309. "\n\t\tPesto "+
  310. "\n\t\tBechamel \n" +
  311. "Answer: ";
  312. }
  313. public String chooseTopping() {
  314. String topping="";
  315. boolean flag=true;
  316. while(flag==true) {
  317. System.out.print("Pick Topping from the list above ");
  318.  
  319. int choice=keyboard.nextInt();
  320.  
  321. switch (choice) {
  322. case 1:
  323. topping="Onion";
  324. break;
  325. case 2:
  326. topping="Olives";
  327. break;
  328. case 3:
  329. topping="Tomato";
  330. break;
  331. case 4:
  332. topping="Mushrooms";
  333. break;
  334. case 5:
  335. topping="Green Peppers";
  336. break;
  337. case 6:
  338. topping="Pepperoni";
  339. break;
  340. }
  341. if(currentToppings.contains(topping)) {
  342. System.out.println("You already have this topping please Select new topping");
  343. flag=true;
  344. }else {
  345. currentToppings+=" "+topping;
  346.  
  347. flag=false;
  348. }
  349.  
  350. }
  351.  
  352. return currentToppings;
  353. }
  354.  
  355.  
  356.  
  357.  
  358.  
  359. public void chooseCheese() {
  360.  
  361. }
  362. public String determineTopping() {
  363. return currentToppings;
  364.  
  365. }
  366. public void setSauce(String sauce) {
  367. boolean sauceflag=true;
  368. while(sauceflag==true) {
  369. if(sauce.equalsIgnoreCase("Salsa")) {
  370. this.sauce="Salsa";
  371. sauceflag=false;
  372. }else if(sauce.equalsIgnoreCase("BBQ")) {
  373. this.sauce="BBQ";
  374. sauceflag=false;
  375. }else if(sauce.equalsIgnoreCase("Tapenade")) {
  376. this.sauce="Tapenade";
  377. sauceflag=false;
  378. }else if(sauce.equalsIgnoreCase("Pesto")) {
  379. this.sauce="Pesto";
  380. sauceflag=false;
  381. }else if(sauce.equalsIgnoreCase("Bechamel")) {
  382. this.sauce="Bechamel";
  383. sauceflag=false;
  384. }else{
  385. System.out.println("This is not a valid response please enter a new one");
  386. sauce=keyboard.next();
  387. sauceflag=true;
  388. }
  389. }
  390. }
  391.  
  392.  
  393. public void setCheese(String cheese) {
  394. boolean cheeseflag=true;
  395. while(cheeseflag==true) {
  396. if(cheese.equalsIgnoreCase("Y")) {
  397. this.cheese="extra cheese";
  398. cheeseflag=false;
  399. }else if(cheese.equalsIgnoreCase("N")){
  400. this.cheese="normal cheese";
  401. cheeseflag=false;
  402. }else {
  403. System.out.println("This is not a valid response please enter a new one");
  404. cheese=keyboard.next();
  405. cheeseflag=true;
  406. }
  407. }
  408. }
  409.  
  410. public void setNumOfToppings(int numOfToppings) {
  411. this.numOfToppings=numOfToppings;
  412. }
  413.  
  414. public String getSauce() {
  415. return sauce;
  416. }
  417.  
  418. public String getCheese() {
  419. return cheese;
  420.  
  421. }
  422. public int getNumOfToppings() {
  423. return numOfToppings;
  424.  
  425. }
  426.  
  427. }
  428.  
  429. ===========================================================================================
  430. PizzaDriver.java
  431. ===========================================================================================
  432. /*
  433. *File name: Customer.java
  434. *
  435. *Programmer: Derek Townsend
  436. *ULID: djtown1
  437. *
  438. *Date: Oct 26, 2017
  439. *
  440. *Class: IT 168
  441. *Lecture Section: 004
  442. *Lecture Instructor:Dr Xing Fang
  443. *Lab Section: 005
  444. *Lab Instructor: Simran Kaur
  445. */
  446. package edu.ilstu;
  447.  
  448. /*
  449. *Keeps track of the customer name, address, and phone number.
  450. *
  451. * @author Derek
  452. *
  453. */
  454. public class Customer
  455. {
  456. private String fullName,address,phoneNumber;
  457.  
  458. public void readInformation(String fullName,String address,String phoneNumber){
  459. this.fullName=fullName;
  460. this.address=address;
  461. this.phoneNumber=phoneNumber;
  462. }
  463.  
  464. public String getFullName() {
  465. return fullName;
  466. }
  467. public String getAddress() {
  468. return address;
  469. }
  470. public String getPhoneNumber() {
  471. return phoneNumber;
  472. }
  473. public String toString() {
  474. return fullName+" "+address+" "+phoneNumber;
  475. }
  476. }
  477.  
  478. ===========================================================================================
  479. PizzaDriver.java
  480. ===========================================================================================
  481. /*
  482. *File name: Store.java
  483. *
  484. *Programmer: Derek Townsend
  485. *ULID: djtown1
  486. *
  487. *Date: Oct 26, 2017
  488. *
  489. *Class: IT 168
  490. *Lecture Section: 004
  491. *Lecture Instructor:Dr Xing Fang
  492. *Lab Section: 005
  493. *Lab Instructor: Simran Kaur
  494. */
  495. package edu.ilstu;
  496. ;
  497. /*
  498. *This class will keep track of the store location.
  499. *
  500. * @author Derek
  501. *
  502. */
  503. public class Store
  504. {
  505. private String location;
  506.  
  507. public void pickingLocation(String locationNumber) {
  508.  
  509. if (locationNumber.equals("1")) {
  510. location="207 W North St, Normal IL";
  511. }else if(locationNumber.equals("2")) {
  512. location="305 S Main St, Normal IL";
  513. }else if(locationNumber.equals("3")) {
  514. location="208 Landmark , Bloomington IL ";
  515. }else {
  516. location="";
  517. }
  518.  
  519. }
  520.  
  521. public String getLocation() {
  522. return location;
  523. }
  524.  
  525. public String toString() {
  526. return location;
  527. }
  528.  
  529. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement