Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are going to write a java application that will be used in a coffee shop to

ID: 3872687 • Letter: Y

Question

You are going to write a java application that will be used in a coffee shop to take customer orders and print a simple on screen order summary. Your coffee shop only sells one type and one size coffee for $5 dollars. However, your customers have the option of adding whipped cream and chocolate each for $1 dollar.

Your application takes in customer name, the number of coffees being ordered and whether or not the customer wants whipped cream and/or chocolate on them. It provides a live update of the total price based on customer order and once the order is placed it will provide the customer with an order summary.

Explanation / Answer

CoffeePay.java

import java.util.Scanner;

public class CoffeePay {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.println("Enter the customer name: ");

String name = scan.next();

System.out.println("Enter the number of coffees being ordered: ");

int n = scan.nextInt();

boolean cream[] = new boolean[n];

boolean chocolate[] = new boolean[n];

int total = 0;

for(int i=0;i<n;i++){

total = total + 5;

System.out.println("Enter create to be added to the coffee "+(i+1)+": ");

cream[i] = scan.nextBoolean();

if(cream[i]) {

total = total + 1;

}

System.out.println("Enter chocolate to be added to the coffee "+(i+1)+": ");

chocolate[i] = scan.nextBoolean();

if(chocolate[i]) {

total = total + 1;

}

System.out.println("Total Price: "+total);

}

int price = 0;

System.out.println(" Customer "+name+" Summary");

System.out.println("Order Cream Chocolate Price");

for(int i=0; i<n;i++) {

price = 5;

if(cream[i]) price++;

if(chocolate[i]) price++;

System.out.printf("%s %10s %10s %10s ","Coffee"+(i+1),cream[i],chocolate[i],price );

}

System.out.println("Total Price: "+total);

}

}

Output:

Enter the customer name:

Suresh

Enter the number of coffees being ordered:

2

Enter create to be added to the coffee 1:

true

Enter chocolate to be added to the coffee 1:

false

Total Price: 6

Enter create to be added to the coffee 2:

true

Enter chocolate to be added to the coffee 2:

true

Total Price: 13

Customer Suresh Summary

Order Cream Chocolate Price

Coffee1 true false 6

Coffee2 true true 7

Total Price: 13

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote