Advertisement
Guest User

dfghbb

a guest
Mar 30th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4. * CS121 Spring 2020
  5. * Project 2 - Etown Cafe
  6. *
  7. * @author Sean O'Brien
  8. * @since 4/3/2020
  9. *
  10. */
  11. public class EtownCafe {
  12.  
  13. // all the drink names
  14. static String[] drinkNames = {"*No Selection*", "Cappuccino", "Espresso", "Chai Latte", "Matcha Green Tea Lattle",
  15. "English Breakfask Tea", "Hot Chocolate", "Apple Juice", "Cold Coffee", "Iced Tea"};
  16.  
  17. // the corresponding drink prices
  18. static double[] drinkPrices = {0.00, 5.50, 4.99, 3.99, 4.50, 4.00, 4.50, 2.99, 4.5, 4.00};
  19.  
  20.  
  21. public static void main(String[] args) {
  22.  
  23. Scanner in = new Scanner(System.in);
  24.  
  25. String customerName = "";
  26. double totalCost = 0;
  27. int i = 0;
  28. int m = 0;
  29.  
  30. System.out.println("***** Welcome to Etown Cafe! *****");
  31. System.out.print("What's your first name?");
  32. customerName = in.nextLine();
  33.  
  34.  
  35. displayMenu();
  36.  
  37.  
  38. System.out.print(customerName + ", how many drinks would you like to order?");
  39. int orders = in.nextInt();
  40.  
  41. System.out.println();
  42.  
  43. if(orders == 0) {
  44. System.out.print("You didn't order any drinks.");
  45. }
  46. else {
  47.  
  48.  
  49. int[] drinkOrders = new int[orders];
  50. for( i = 0 ; i < orders; i++) {
  51. System.out.print("Please enter a drink # for order " + (i+1) + ":");
  52. drinkOrders[i] = in.nextInt();
  53. }
  54.  
  55. System.out.println();
  56.  
  57. System.out.println("Your order consists of:");
  58. for(int j = 0 ;j < drinkOrders.length; j++) {
  59. System.out.printf(drinkNames[drinkOrders[j]] + " -- $" + " %.2f\n", drinkPrices[drinkOrders[j]]);
  60. }
  61. }
  62. System.out.println();
  63.  
  64. // TODO: getting the total cost by calling the getTotalCost() method
  65. totalCost = getTotalCost();
  66.  
  67. // print out the total cost
  68. System.out.printf("\nThank you, %s. Your order is $%.2f dollars in total.", customerName, totalCost);
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76. /**
  77. * display the drinks menu
  78. * */
  79. public static void displayMenu() {
  80.  
  81. System.out.println();
  82. System.out.println("** Etown cafe menu **");
  83.  
  84. for (int i = 0; i < drinkNames.length; i++) {
  85. System.out.printf(i + ". " + drinkNames[i] + " -- $" + " %.2f\n",drinkPrices[i]);
  86. }
  87.  
  88.  
  89.  
  90.  
  91. System.out.println();
  92.  
  93. }
  94.  
  95.  
  96. /**
  97. * Calculate the total cost of the drink orders.
  98. * @param orders - an array of drink indices ordered by the customer
  99. * @return total - the total cost of the drink orders
  100. * */
  101. public static double getTotalCost(int[] orders) {
  102. double total = 0.0;
  103.  
  104. // TODO: compute the total cost of the drink orders
  105. for(int i = 0 ; i < orders.length; i++) {
  106. total = total + orders[i];
  107. }
  108.  
  109.  
  110. return total;
  111. }
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement