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

import java.io.BufferedReader; import java.io.InputStreamReader; import java.uti

ID: 3741557 • Letter: I

Question

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.util.Scanner;

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

/**

*

* @author

*/

public class YogurtBillCalculator {

  

/**

* @param args the command line arguments

*/

private static final float YOGURT_COST = 0.44F;

private static final float WAFFLE_CONE_COST = 0.61F;

private static final float TOPPING_COST = 0.53F;

private static final int NO_ORDER_FOR_DISCOUNT = 10;

private static final int DISCOUNT_RATE = 5;

public static void main(String[] args) throws NumberFormatException, Exception {

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

int noOfYogurt = 0;

int noOfToppings = 0;

int cupChoice = 0;

float yogurtCost, coneCost, toppingCost;

char extraToppings;

System.out.println("Yogurt Bill Calculator");

System.out.println("");

System.out.println("Enter yogurt weight (whole ounces):");

noOfYogurt = Integer.parseInt(br.readLine());

System.out.println("Do you want toppings (Y or N)?");

extraToppings = br.readLine().charAt(0);

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

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

noOfToppings = Integer.parseInt(br.readLine());

}

System.out.println("Enter 1 for a plastic cup or 2 for a waffle cone:");

cupChoice = Integer.parseInt(br.readLine());

String coneOrCup = (cupChoice == 1 ? " cup" : "cone");

coneCost = (cupChoice == 1 ? 0 : WAFFLE_CONE_COST);

System.out.println(); System.out.println(); // Display 2 blank lines after reading all inputs

System.out.println("YOGURT ORDER");

if(noOfYogurt < 10) {

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

}

if(noOfYogurt > 10) {

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

}

System.out.printf("%-21s%s ","Container:", coneOrCup);

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

System.out.println(""); // Display a blank line

System.out.println("YOGURT BILL");

yogurtCost = noOfYogurt * YOGURT_COST;

toppingCost = noOfToppings * TOPPING_COST;

System.out.printf("%-20s %.2f ","Yogurt Cost:",yogurtCost);

if (coneCost > 0){

System.out.printf("%-20s %.2f ","Cone cost:",coneCost);

}

System.out.printf("%-18s+ %.2f ","Topping cost:",toppingCost); //plus sign

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

float totalCost = yogurtCost + toppingCost + coneCost;

if(totalCost < 10) {

System.out.printf("%-21s%.2f ","",totalCost);

}

if(totalCost > 10) {

System.out.printf("%-20s%.2f ","",totalCost);

}

// Check if Discount is possible

if (noOfYogurt > NO_ORDER_FOR_DISCOUNT){

float discount = (DISCOUNT_RATE/100.00F) * totalCost;

System.out.printf("%-18s- %.2f ","Discount:",discount);

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

if(totalCost - discount < 10 ) {

System.out.printf("%-21s%.2f ","",totalCost - discount);

}

if(totalCost - discount > 10) {

System.out.printf("%-20s%.2f ","",totalCost - discount);

}

}

}

}

I need to extend my current program to make it look like example below:

? In addition to frozen yogurt, the store has added ice cream to the menu.

o Yogurt will now cost:

? 0.44 per ounce, if amount purchased is less than 10 oz

? 0.41 per ounce, if the amount purchased is 10 or more oz

o Ice cream will cost:

? 0.51 per ounce, if amount purchased is less than 10 oz

? 0.47 per ounce, if the amount purchased is 10 or more oz

? The container options have also been expanded. Single servings may be purchased in:

o a plastic cup for free

o a sugar cone for an additional $0.25

o a waffle cone for an additional $0.50

o a souvenir bowl for an additional $0.75

? Customers may still optionally add toppings to their frozen treats with new pricing:

o $0.50 per topping for 1 – 2 toppings

o $0.45 per topping for 3 – 4 toppings

o $0.40 per topping for more than 4 toppings

? Since the discount is now built into the cost per ounce,

the discount will no longer be computed separately.

? Include actual program description/author comments, instead of the default comments

and modify them to describe the changes from the last program.

? Code at least one of each of the following types of statements, where appropriate:

o a nested if statement

o a multiple alternative if statement

o a switch statement with a default case

Read all the inputs from the users, after creating appropriate variables to hold each answer.

Inputs are:

? Whether the customer wants (1) frozen yogurt or (2) ice cream

o After reading the user input, use a decision to assign a value to a String variable that will

hold a String description of the treat type chosen.

? The number of ounces of purchased (include the customer’s treat type in the prompt)

? How many toppings the customer wants to add (customer will enter 0 for no toppings)

? What kind of container the customer wants

o After reading the user input, use a decision to assign a value to a String variable to hold a

description of the container chosen

example of reading inputs:

Frozen Treat Bill Calculator

Enter 1 for frozen yogurt or 2 for ice cream:

2

Enter ice cream weight (whole ounces):

15

How many toppings?

6

Container options are

C - plastic cup

S - sugar cone

W - waffle cone

B - souvenir bowl

Enter choice:

B

Display 2 blank lines after reading all inputs. Then display an order summary.

? All order details should line up on the right with the last character in position 30.

? The treat type should be displayed as a String.

? The container type should be displayed as a String.

ORDER

Treat type: ice cream

Weight (oz): 15

Container: souvenir bowl

Number Toppings: 6

? Treat cost per ounce

? Cost per topping

? Container cost

Use decisions to control the following:

o Do not display the container cost, if container cost is 0.00 (i.e. plastic cup).

o Do not display the topping cost, if topping cost is 0.00 (i.e. no toppings were chosen).

o Do not display the dividing line and total cost if both container and toppings costs were 0

(so only display the treat cost if there are no container or toppings costs)

BILL

Treat cost: 7.05

Container Cost: 0.75

Topping Cost: 2.40

-------

Total 10.20

EXAMPLE RUN

Frozen Treat Bill Calculator

Enter 1 for frozen yogurt or 2 for ice cream:

1

Enter frozen yogurt weight (whole ounces):

8

How many toppings?

0

Container options are

C - plastic cup

S - sugar cone

W - waffle cone

B - souvenir bowl

Enter choice:

c

ORDER

Treat type: frozen yogurt

Weight (oz): 8

Container: plastic cup

Number Toppings: 0

BILL

Treat cost: 3.52

Explanation / Answer

This is the answer for this with all the requirements.if you have any doubts or if i have missed something please let me know

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote