Hello, I am having trouble getting my files to work together for this problem. Here is the question and thank you for taking the time to answer it :)
(1) Write an application that displays a menu of three items for the Jivin’ Java Coffee Shop as follows:
American 1.99
Expresso 2.50
Latte 2.15
Prompt the user to choose an item using the number (1, 2, or 3) that corresponds to the item, or to enter 0 to quit the application.
After the user makes the first selection, if the choice is 0, display a total bill of $0.
Otherwise, display the menu again.
The user should respond to this prompt with another item number to order or 0 to quit.
If the user types 0, display the cost of the single requested item.
If the user types 1, 2, or 3, add the cost of the second item to the first, and then display the menu a third time.
If the user types 0 to quit, display the total cost of the two items; otherwise, display the total for all three selections.
Save the file as Coffee.java.
(2)
Need a CoffeeTest.java Class that has the main method and an object to use the Coffee class.
CoffeeTest.java
import java.text.DecimalFormat;
import java.util.Scanner;
public class CoffeeTest {
public static void main(String[] args) {
Coffee c = new Coffee();
Scanner scan = new
Scanner(System.in);
System.out.println("1.American
1.99\n2.Expresso 2.50\n3.Latte 2.15\nEnter your choice(0 to quit):
");
int choice = scan.nextInt();
while(choice!=0){
c.add(choice);
System.out.println("1.American 1.99\n2.Expresso 2.50\n3.Latte
2.15\nEnter your choice(0 to quit): ");
choice =
scan.nextInt();
}
DecimalFormat df = new
DecimalFormat("0.00");
System.out.println("Total bill is
$"+df.format(c.getTotal()));
}
}
Coffee.java
public class Coffee {
private String items[] = {"American", "Expresso",
"Latte"};
private double prices[] = {1.99, 2.50, 2.15};
double totalPrice = 0;
public Coffee(){
}
public void add(int choice){
totalPrice = totalPrice +
prices[choice-1];
}
public double getTotal(){
return totalPrice;
}
}
Output:
1.American 1.99
2.Expresso 2.50
3.Latte 2.15
Enter your choice(0 to quit):
2
1.American 1.99
2.Expresso 2.50
3.Latte 2.15
Enter your choice(0 to quit):
3
1.American 1.99
2.Expresso 2.50
3.Latte 2.15
Enter your choice(0 to quit):
0
Total bill is $4.65
Get Answers For Free
Most questions answered within 1 hours.