Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with my code. I need it fixed to read the inputs properly. Frozen Treat Bill Calculator Enter 1 for frozen yogurt or

I need help with my code. I need it fixed to read the inputs properly.

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

Weight (oz): 10

Container: plastic cup

Number Toppings: 5

BILL Treat cost: 4.70

Topping Cost: 2.00

-------

Total 6.70

User input should be lined up at 25.

I need the appropriate math to equate costs.

everything else should be easily found in my code.

Thanks for help!

import java.util.Scanner;

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

public class YogurtBillCalculatorV2 {

static final float YOGURT_COST = 0.44F;

static final float YOGURT_COST_FOR_QUANTITY_MORE_THAN_10 = 0.41F;

static final float ICECREAM_COST = 0.44F;

static final float ICECREAM_COST_FOR_QUANTITY_MORE_THAN_10 = 0.41F;

static final float SUGAR_CONE_COST = 0.25F;

static final float WAFFLE_CONE_COST = 0.50F;

static final float SOUVENIR_BOWL_COST = 0.75F;

static final float PLASTIC_CUP_COST = 0.00F;

static final float TOPPING_COST_FOR_1_TO_2 = 0.50F;

static final float TOPPING_COST_FOR_3_TO_4 = 0.45F;

static final float TOPPING_COST_FOR_MORE_THAN_4 = 0.40F;

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int item;

int noOfToppings = 0;

float ItemCost = 0;

float ContainerCost = 0;

int extraToppings;

String itemName = null;

String ContainerName = null;

char ContainerOption = 0;

System.out.println("Frozen Treat Bill Calculator");

System.out.println("Enter 1 for frozen yogurt or 2 for ice cream:");

item = scnr.nextInt();

//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):");

int noOfItems = scnr.nextInt();

//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 = scnr.nextInt();

//if the user enters y then accepts the number of toppings

if (extraToppings == 'y' || extraToppings == 'Y') {

System.out.println("How many toppings?");

noOfToppings = scnr.nextInt();

}

//prompt the user to enter the choice of container

System.out.print("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.printf("%-24s ","Treat type: ", itemName);

System.out.printf("%-24s%d ","Weight (oz):",noOfItems);

System.out.printf("%-24s ","Container: ",ContainerName);

System.out.printf("%-24s%d ", "Number Toppings:",noOfToppings);

System.out.println("");

//display the bill if the there is discount calculate the discount and display

System.out.println("BILL");

System.out.println("Treat cost");

if (noOfToppings == 1 || noOfToppings == 2) {

System.out.println(noOfToppings * TOPPING_COST_FOR_1_TO_2);

}

if (noOfToppings == 3 || noOfToppings == 4) {

System.out.println(noOfToppings * TOPPING_COST_FOR_3_TO_4);

}

if (noOfToppings > 4) {

System.out.println(noOfToppings * TOPPING_COST_FOR_MORE_THAN_4);

}

if (ContainerCost > 0) {

System.out.printf("%-24s%d ","Container Cost:"); //edit math

}

if (extraToppings > 0) {

System.out.printf("%-24s%d ","Topping Cost:");

}

System.out.printf("%-24s ","", "-------");

System.out.printf("%-24s ","", "Total"); //edit math

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

3. Evaluate your listeners and tailor your speech to them

Answered: 1 week ago