/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;
import java.text.DecimalFormat;
// This program will calculate the cost of someone's order at a coffee shop with applied possible discounts and tax
class CoffeeShopWithMethods
{
static Scanner user_input
= new Scanner
(System.
in); static double Discounted_cost = 0.0;
static double Total_cost = 0.0;
static double tax = 0.0;
static double cost = 0.0;
static double discount = 0.0;
public static void main
(String [] args
) {
System.
out.
print("\nEnter your username: "); username = user_input.nextLine();
System.
out.
print ("\nWelcome to Casey's Classic Coffee, " + username
+ "! \n");
//call methods
displayMenu();
displayOutput();
System.
out.
println("\nThank you " + username
+ "! Have a nice day!"); }
//outputs the menu to the screen
public static void displayMenu()
{
System.
out.
println ("\n\tItem\t\tCost\n\t1. Coffee\t$1.50\n\t2. Latte\t$3.50\n\t3. Cappuccino\t$3.25\n\t4. Espresso\t$2.00"); }
//prompts the user to enter item number, returns user input
public static int getItemNumber() //error: ; expected
{
System.
out.
print ("\nPlease enter the desired item number: "); return user_input.nextInt();
}
//prompts user to enter quantity, returns user input
public static int getQuantity() //error: ; expected
{
System.
out.
print ("\nPlease enter the quantity: "); return user_input.nextInt();
}
//takes the item number and quantity and returns the subtotal
public static double computeSubTotal () //error: ; expected
{
int number = getItemNumber();
int quantity = getQuantity();
// Used final double in order to make coffee shop items constant
final double COFFEE = 1.50;
final double LATTE = 3.50;
final double CAPPUCCINO = 3.25;
final double ESPRESSO = 2.00;
//double cost = 0;
if (number == 1)
cost = quantity * COFFEE;
else if (number == 2)
cost = quantity * LATTE;
else if (number == 3)
cost = quantity * CAPPUCCINO;
else if (number == 4)
cost = quantity * ESPRESSO;
return cost;
}
//takes the subtotal and returns true if the user earned a discount; otherwise, returns false
public static boolean discountCheck () //error: ; expected
{
if (cost >= 10)
return true;
return false;
}
//takes the subtotal and returns the dollar amount of the discount earned by the user
public static double computeDiscount () //error: ; expected
{
if (discountCheck())
{
discount = cost * 0.10;
}
else
{
discount = 0;
}
return discount;
}
//takes the subtotal and the discount amount and returns the price after the discount is applied
public static double computePriceAfterDiscount () //error: ; expected
{
//double discount = 0;
//double Discounted_cost = 0;
Discounted_cost = cost - discount;
return Discounted_cost;
}
//takes the prices after the discount is applied and tax rate and returns the tax amount
public static double computeTax() //error: ; expected
{
tax = Discounted_cost * 0.07;
return tax;
}
//takes the price after the discount is applied and the tax amount and returns the final total
public static double computeTotal() //says ; expected
{
Total_cost = Discounted_cost + tax;
return Total_cost;
}
//takes the subtotal, discount amount, price after discount, tax, and final total and displays all the lines of output to the user
public static void displayOutput() //says ; expected at the end of method header
{
//call methods
cost = computeSubTotal();
discount = computeDiscount();
Discounted_cost = computePriceAfterDiscount();
tax = computeTax();
Total_cost = computeTotal();
System.
out.
printf ("\nTotal before discount and tax: $%.2f\n ", cost
);
System.
out.
printf("\nCalculated discount: $%.2f\n", discount
); System.
out.
printf("\nTotal after special discount: $%.2f\n", Discounted_cost
);
System.
out.
printf("\nTax: $%.2f\n", tax
); System.
out.
printf ("\nTotal cost: $%.2f\n", Total_cost
); }
}