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

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;

System.out.printf("%-21s%.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 ","","-------");

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

}

}

}


I need the below requirements added to my code. Any help would be appreciated.

The local frozen yogurt shop you wrote the program for in Topic would like you to modify the program to handle an extended menu.
? 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.

Explanation / Answer


Given below is the modified code for the question.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
Please do rate the answer if it was helpful. Thank you
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 SUGAR_CONE_COST = 0.25F;
private static final float WAFFLE_CONE_COST = 0.50F;
private static final float SOVENIR_BOWL_COST = 0.75F;
public static void main(String[] args) throws NumberFormatException, Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int weight = 0;
int noOfToppings = 0;
int cupChoice = 0;
float treatCost = 0 , containerCost = 0, toppingCost = 0;
char extraToppings;
String treat = "";
System.out.println("Frozen Treat Bill Calculator");
System.out.println("");
System.out.println("What would you like to have ? 1 for Yogurt 2 for Icecream");
int treatChoice = Integer.parseInt(br.readLine());

System.out.println("Enter weight (whole ounces):");
weight = Integer.parseInt(br.readLine());
if(treatChoice == 1)
{
treat = "Yogurt";
if(weight < 10)
treatCost = 0.44F * weight;
else
treatCost = 0.41F * weight;
}
else
{
treat = "Ice cream";
if(weight < 10)
treatCost = 0.51F * weight;
else
treatCost = 0.47F * weight;
}
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());
if(noOfToppings <= 2)
toppingCost = 0.50F * noOfToppings;
else if(noOfToppings <= 4)
toppingCost = 0.45F * noOfToppings;
else
toppingCost = 0.4F * noOfToppings;
}
System.out.println("Enter 1 for a plastic cup or 2 for a sugar cone or 3 for waffle cone or 4 for sovenir bowl:");
cupChoice = Integer.parseInt(br.readLine());
String coneOrCup = "";
if(cupChoice == 1)
{
containerCost = 0;
coneOrCup = "Plastic cup";
}
else if(cupChoice == 2)
{
containerCost = SUGAR_CONE_COST;
coneOrCup = "Sugar cone";
}
else if(cupChoice == 3)
{
containerCost = WAFFLE_CONE_COST;
coneOrCup = "Waffle cone";
}
else if(cupChoice == 4)
{
containerCost = SOVENIR_BOWL_COST;
coneOrCup = "Sovenir bowl";
}



System.out.println(" "); // Display 2 blank lines after reading all inputs
System.out.println("YOGURT ORDER");
System.out.printf("%-25s%d ","Weight (oz): ", weight);
System.out.printf("%-25s%s ","Container:", coneOrCup);
System.out.printf("%-25s%d ","Number Toppings:", noOfToppings);
System.out.println(""); // Display a blank line
System.out.println("YOGURT BILL");


System.out.printf("%-25s %.2f ", treat + " Cost:",treatCost);
if (containerCost > 0){
System.out.printf("%-25s %.2f ","Container cost:",containerCost);
}
System.out.printf("%-23s+ %.2f ","Topping cost:",toppingCost); //plus sign
System.out.printf("%-25s %s ","","-------");
float totalCost = treatCost + toppingCost + containerCost;
System.out.printf("%-25s %.2f ","",totalCost);

}
}


output
Frozen Treat Bill Calculator
What would you like to have ? 1 for Yogurt 2 for Icecream
1
Enter weight (whole ounces):
12
Do you want toppings (Y or N)?
y
How many toppings?
3
Enter 1 for a plastic cup or 2 for a sugar cone or 3 for waffle cone or 4 for sovenir bowl:
3

YOGURT ORDER
Weight (oz): 12
Container: Waffle cone
Number Toppings: 3
YOGURT BILL
Yogurt Cost: 4.92
Container cost: 0.50
Topping cost: + 1.35
-------
6.77

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