Advertisement
Guest User

Little Ceasers

a guest
Mar 21st, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. import java.util.Scanner; // Needed for the Scanner class
  2.  
  3. /**
  4. This program allows the user to order a pizza.
  5. */
  6.  
  7. public class PizzaOrder
  8. {
  9. public static void main (String[] args)
  10. {
  11. // Create a Scanner object to read input.
  12. Scanner keyboard = new Scanner (System.in);
  13.  
  14. String firstName; // User's first name
  15. boolean discount = false; // Flag for discount
  16. int inches; // Size of the pizza
  17. char crustType; // For type of crust
  18. String crust = "Hand-tossed"; // Name of crust
  19. double cost = 12.99; // Cost of the pizza
  20. final double TAX_RATE = .08; // Sales tax rate
  21. double tax; // Amount of tax
  22. char choice; // User's choice
  23. String input; // User input
  24. String toppings = "Cheese "; // List of toppings
  25. int numberOfToppings = 0; // Number of toppings
  26.  
  27. // Prompt user and get first name.
  28. System.out.println("Welcome to Mike and " +
  29. "Diane's Pizza");
  30. System.out.println("Enter your first name: ");
  31. firstName = keyboard.nextLine();
  32.  
  33. // Determine if user is eligible for discount by
  34. // having the same first name as one of the owners.
  35. // ADD LINES HERE FOR TASK #1
  36.  
  37. // Prompt user and get pizza size choice.
  38. System.out.println("Pizza Size (inches) Cost");
  39. System.out.println(" 10 $10.99");
  40. System.out.println(" 12 $12.99");
  41. System.out.println(" 14 $14.99");
  42. System.out.println(" 16 $16.99");
  43. System.out.println("What size pizza " +
  44. "would you like?");
  45. System.out.print("10, 12, 14, or 16 " +
  46. "(enter the number only): ");
  47. inches = keyboard.nextInt();
  48.  
  49. // Set price and size of pizza ordered.
  50. // ADD LINES HERE FOR TASK #2
  51.  
  52. // Consume the remaining newline character.
  53. keyboard.nextLine();
  54.  
  55. // Prompt user and get crust choice.
  56. System.out.println("What type of crust " +
  57. "do you want? ");
  58. System.out.print("(H)Hand-tossed, " +
  59. "(T) Thin-crust, or " +
  60. "(D) Deep-dish " +
  61. "(enter H, T, or D): ");
  62. input = keyboard.nextLine();
  63. crustType = input.charAt(0);
  64.  
  65. // Set user's crust choice on pizza ordered.
  66. // ADD LINES FOR TASK #3
  67.  
  68. // Prompt user and get topping choices one at a time.
  69. System.out.println("All pizzas come with cheese.");
  70. System.out.println("Additional toppings are " +
  71. "$1.25 each, choose from:");
  72. System.out.println("Pepperoni, Sausage, " +
  73. "Onion, Mushroom");
  74.  
  75. // If topping is desired,
  76. // add to topping list and number of toppings
  77. System.out.print("Do you want Pepperoni? (Y/N): ");
  78. input = keyboard.nextLine();
  79. choice = input.charAt(0);
  80. if (choice == 'Y' || choice == 'y')
  81. {
  82. numberOfToppings += 1;
  83. toppings = toppings + "Pepperoni ";
  84. }
  85. System.out.print("Do you want Sausage? (Y/N): ");
  86. input = keyboard.nextLine();
  87. choice = input.charAt(0);
  88. if (choice == 'Y' || choice == 'y')
  89. {
  90. numberOfToppings += 1;
  91. toppings = toppings + "Sausage ";
  92. }
  93. System.out.print("Do you want Onion? (Y/N): ");
  94. input = keyboard.nextLine();
  95. choice = input.charAt(0);
  96. if (choice == 'Y' || choice == 'y')
  97. {
  98. numberOfToppings += 1;
  99. toppings = toppings + "Onion ";
  100. }
  101. System.out.print("Do you want Mushroom? (Y/N): ");
  102. input = keyboard.nextLine();
  103. choice = input.charAt(0);
  104. if (choice == 'Y' || choice == 'y')
  105. {
  106. numberOfToppings += 1;
  107. toppings = toppings + "Mushroom ";
  108. }
  109.  
  110. // Add additional toppings cost to cost of pizza.
  111. cost = cost + (1.25 * numberOfToppings);
  112.  
  113. // Display order confirmation.
  114. System.out.println();
  115. System.out.println("Your order is as follows: ");
  116. System.out.println(inches + " inch pizza");
  117. System.out.println(crust + " crust");
  118. System.out.println(toppings);
  119.  
  120. // Apply discount if user is eligible.
  121. // ADD LINES FOR TASK #4 HERE
  122.  
  123. // EDIT PROGRAM FOR TASK #5
  124. // SO ALL MONEY OUTPUT APPEARS WITH 2 DECIMAL PLACES
  125. System.out.printf("The cost of your order " +
  126. "is: $%f\n", cost);
  127.  
  128. // Calculate and display tax and total cost.
  129. tax = cost * TAX_RATE;
  130. System.out.printf("The tax is: $%f\n", tax);
  131. System.out.printf("The total due is: $%f\n",
  132. (tax + cost));
  133.  
  134. System.out.println("Your order will be ready " +
  135. "for pickup in 30 minutes.");
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement