Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- * CS121 Spring 2020
- * Project 2 - Etown Cafe
- *
- * @author Sean O'Brien
- * @since 4/3/2020
- *
- */
- public class EtownCafe {
- // all the drink names
- static String[] drinkNames = {"*No Selection*", "Cappuccino", "Espresso", "Chai Latte", "Matcha Green Tea Lattle",
- "English Breakfask Tea", "Hot Chocolate", "Apple Juice", "Cold Coffee", "Iced Tea"};
- // the corresponding drink prices
- static double[] drinkPrices = {0.00, 5.50, 4.99, 3.99, 4.50, 4.00, 4.50, 2.99, 4.5, 4.00};
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- String customerName = "";
- double totalCost = 0;
- int i = 0;
- int m = 0;
- System.out.println("***** Welcome to Etown Cafe! *****");
- System.out.print("What's your first name?");
- customerName = in.nextLine();
- displayMenu();
- System.out.print(customerName + ", how many drinks would you like to order?");
- int orders = in.nextInt();
- System.out.println();
- if(orders == 0) {
- System.out.print("You didn't order any drinks.");
- }
- else {
- int[] drinkOrders = new int[orders];
- for( i = 0 ; i < orders; i++) {
- System.out.print("Please enter a drink # for order " + (i+1) + ":");
- drinkOrders[i] = in.nextInt();
- }
- System.out.println();
- System.out.println("Your order consists of:");
- for(int j = 0 ;j < drinkOrders.length; j++) {
- System.out.printf(drinkNames[drinkOrders[j]] + " -- $" + " %.2f\n", drinkPrices[drinkOrders[j]]);
- }
- }
- System.out.println();
- // TODO: getting the total cost by calling the getTotalCost() method
- totalCost = getTotalCost();
- // print out the total cost
- System.out.printf("\nThank you, %s. Your order is $%.2f dollars in total.", customerName, totalCost);
- }
- /**
- * display the drinks menu
- * */
- public static void displayMenu() {
- System.out.println();
- System.out.println("** Etown cafe menu **");
- for (int i = 0; i < drinkNames.length; i++) {
- System.out.printf(i + ". " + drinkNames[i] + " -- $" + " %.2f\n",drinkPrices[i]);
- }
- System.out.println();
- }
- /**
- * Calculate the total cost of the drink orders.
- * @param orders - an array of drink indices ordered by the customer
- * @return total - the total cost of the drink orders
- * */
- public static double getTotalCost(int[] orders) {
- double total = 0.0;
- // TODO: compute the total cost of the drink orders
- for(int i = 0 ; i < orders.length; i++) {
- total = total + orders[i];
- }
- return total;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement