Question
Fix my code to make it read like the table below. Frozen Treat Bill Calculator Enter 1 for frozen yogurt or 2 for ice cream:
Fix my code to make it read like the table below.
Frozen Treat Bill Calculator
Enter 1 for frozen yogurt or 2 for ice cream:
Enter ice cream weight (whole ounces):
How many toppings?
Container options are
C - plastic cup
S - sugar cone
W - waffle cone
B - souvenir bowl
Enter choice:
ORDER
Treat type: ice cream //user input
Weight (oz): 15 //user input
Container: souvenir bowl //user input
Number Toppings: 6 //user input
*Spacing after : needs to line up at 25
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class YogurtBillCalculatorV2 {
private static final float YOGURT_COST = 0.44F;
private static final float YOGURT_COST_FOR_QUANTITY_MORE_THAN_10 = 0.41F;
private static final float ICECREAM_COST = 0.44F;
private static final float ICECREAM_COST_FOR_QUANTITY_MORE_THAN_10 = 0.41F;
private static final float SUGAR_CONE_COST = 0.25F;
private static final float WAFFLE_CONE_COST = 0.50F;
private static final float SOUVENIR_BOWL_COST = 0.75F;
private static final float PLASTIC_CUP_COST = 0.00F;
private static final float TOPPING_COST_FOR_1_TO_2 = 0.50F;
private static final float TOPPING_COST_FOR_3_TO_4 = 0.45F;
private static final float TOPPING_COST_FOR_MORE_THAN_4 = 0.40F;
public static void main(String[] args) throws NumberFormatException, Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int noOfItems = 0;
int item;
int noOfToppings = 0;
float ItemCost = 0;
float ContainerCost = 0;
int extraToppings;
String itemName = null;
String ContainerName = null;
char ContainerOption;
System.out.println("Frozen Treat Bill Calculator");
System.out.println("Enter 1 for frozen yogurt or 2 for ice cream:");
item = Integer.parseInt(br.readLine());
//assign the name to the item name
if (item == 1)
itemName = "frozen yogurt";
if (item == 2)
itemName = "ice cream";
//Prompt the user to enter the item weight
System.out.println("Enter " + itemName + " weight (whole ounces):");
noOfItems = Integer.parseInt(br.readLine());
//cclculate the item cost based on the weight
if (item == 1) {
ItemCost = noOfItems * YOGURT_COST;
}
if (item == 2) {
ItemCost = noOfItems * ICECREAM_COST;
}
//calculate the item cost based on the weight
//prompt the user for toppings
System.out.println("How many toppings?");
extraToppings = Integer.parseInt(br.readLine());
//if the user enters y then accepts the number of toppings
if (extraToppings == 'y' || extraToppings == 'Y') {
System.out.println("How many toppings?");
noOfToppings = Integer.parseInt(br.readLine());
}
//prompt the user to enter the choice of container
System.out.println("Container options are:");
System.out.print(" C - Plastic Cup S - Sugar Cone W - Waffle Cone B - Souvenir Bowl ");
//Calculate the container cost
switch (ContainerOption) {
case 'C':
case 'c':
ContainerName = "plastic cup";
ContainerCost = PLASTIC_CUP_COST;
break;
case 'S':
case 's':
ContainerName = "sugar cone";
ContainerCost = SUGAR_CONE_COST;
break;
case 'W':
case 'w':
ContainerName = "waffle cone";
ContainerCost = WAFFLE_CONE_COST;
break;
case 'B':
case 'b':
ContainerName = "souvenir bowl";
ContainerCost = SOUVENIR_BOWL_COST;
break;
default:
break;
}
System.out.println("Enter Choice:");
System.out.println("" + "");
//Display the order done
System.out.println("ORDER");
System.out.println("Treat Type : " + itemName);
if (noOfItems < 10) {
System.out.println("Weight (oz):" + noOfItems);
}
if (noOfItems > 10) {
System.out.println("Weight (oz): " + noOfItems);
}
System.out.println("Container : " + ContainerName);
System.out.printf("%-24s%d ", "Number Toppings:", noOfToppings);
//display the bill if the there is discount calculate the discount and display
System.out.println("BILL");
System.out.print("Treat Cost");
}
private static float getToppingCost(int noOfToppings) {
if (noOfToppings == 1 || noOfToppings == 2) {
return noOfToppings * TOPPING_COST_FOR_1_TO_2;
}
if (noOfToppings == 3 || noOfToppings == 4) {
return noOfToppings * TOPPING_COST_FOR_3_TO_4;
}
if (noOfToppings > 4) {
return noOfToppings * TOPPING_COST_FOR_MORE_THAN_4;
}
return 0;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started