Question: Can Someone please correct the code I have, im not sure why it keeps running error saying Candy, Cookie and Icecream cannot be found *****************************************8**this

Can Someone please correct the code I have, im not sure why it keeps running error saying Candy, Cookie and Icecream cannot be found

*****************************************8**this is what the output should be*********************************88*

Peanut Butter Fudge $ 8.98 [Tax: $0.63]

2.25 lbs @ $3.99

Candy Cane $ 0.75 [Tax: $0.05]

0.50 lbs @ $1.50

Oatmeal Raisin Cookies $ 1.33 [Tax: $0.09]

4 cookies @ $3.99 per Dozen

Chocolate Chip Cookies $ 4.25 [Tax: $0.30]

12 cookies @ $4.25 per Dozen

Vanilla Ice Cream $ 2.75

2 scoop(s) @ $1.05/scoop + $0.65

Cherry Garcia Ice Cream $ 5.29

3 scoop(s) @ $1.33/scoop + $1.30

CANDY [ 2] Cost: $ 9.73 Tax: $0.68

COOKIES [ 2] Cost: $ 5.58 Tax: $0.39

ICE CREAM [ 2] Cost: $ 8.04

---- -------- -----

Subtotals [ 6] $23.35 $1.07

========

Total $24.42

****************************************************************************

package dessertshop; import java.util.*;

import java.text.NumberFormat;

enum Dessertitem {

CANDY, COOKIE, ICECREAM;

}

public class DessertShop {

private Candy candies[] = new Candy[5];

private Cookie cookies[] = new Cookie[5];

private IceCream IceCreams[] = new IceCream[5];

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

/*

* Candy item1 = new Candy("Penut Butter Fudge", 2.25, 3.99); Cookie item2 = new

* Cookie ("Oatmeal Raisin Cookies ", 4, 3.99); IceCream item3 = new IceCream (

* "Vanilla Ice Cream", 2, 1.05, 0.45);

*

* System.out.println( item1 ); System.out.println( item2 ); System.out.println(

* item3 );

*/

Dessertitem Choice;

String name;

int number;

double price, toppingPrice = 0, totalCandy = 0, totalTaxCandy = 0, totalIceCream = 0, totalTaxIceCream = 0,

totalCookie = 0, totalTaxCookie = 0, numPounds;

int candiesCount = 0, cookiesCount = 0, iceCreamCount = 0;

String choiceStr;

DessertShop dessertshop = new DessertShop();

do {

System.out

.println(" Enter Desert Type: 1.Candy 2.Cookie 3.Ice Cream 4 Type Enter To Get Reciept ");

Scanner sc = new Scanner(System.in);

choiceStr = sc.nextLine();

if (choiceStr.isEmpty()) {

break;

}

Choice = Dessertitem.valueOf(choiceStr);

switch (Choice) {

case CANDY:

System.out.println("Enter Name of The Candy");

name = sc.nextLine();

if (sc.hasNextLine()) {

sc.nextLine();

}

System.out.println("Enter Number Of Pounds");

numPounds = sc.nextDouble();

System.out.println("Enter price per per pound");

price = sc.nextDouble();

dessertshop.candies[candiesCount++] = new Candy(name, numPounds, price);

break;

case COOKIE:

System.out.println("Enter Name of The Cookie");

name = sc.nextLine();

if (sc.hasNextLine()) {

sc.nextLine();

}

System.out.println("Enter Number Of Cookies");

number = sc.nextInt();

System.out.println("Enter price per Dozen");

price = sc.nextDouble();

dessertshop.cookies[cookiesCount++] = new Cookie(name, number, price);

break;

case ICECREAM:

System.out.println("Enter Name of The Ice Cream");

name = sc.nextLine();

if (sc.hasNextLine()) {

sc.nextLine();

}

System.out.println("Enter Number Of Scoops");

number = sc.nextInt();

System.out.println("Enter price per Scoop");

price = sc.nextDouble();

System.out.println("Enter price per Topping");

toppingPrice = sc.nextDouble();

dessertshop.IceCreams[iceCreamCount++] = new IceCream(name, number, price, toppingPrice);

break;

}

} while (true);

for (int i = 0; i < iceCreamCount; i++) {

totalIceCream += (dessertshop.IceCreams[i].getCost());

System.out.println(dessertshop.IceCreams[i].toString());

System.out.write(dessertshop.IceCreams[i].toString() + " ");

}

NumberFormat formatter = NumberFormat.getCurrencyInstance();

System.out.println("CANDY [" + candiesCount + "] Cost: " + formatter.format(totalCandy) + " Tax: "

+ formatter.format(totalTaxCandy));

System.out.println("COOKIES [" + cookiesCount + "] Cost: " + formatter.format(totalCookie) + " Tax: "

+ formatter.format(totalTaxCookie));

System.out.println("ICECREAM [" + iceCreamCount + "] Cost: " + formatter.format(totalIceCream));

System.out.println("------------------------------------------------");

System.out.println("SubTotals [" + (candiesCount + iceCreamCount + cookiesCount) + "] "

+ formatter.format(totalCandy + totalCookie + totalIceCream) + " "

+ formatter.format(totalTaxCandy + totalTaxCookie));

System.out.println("================================================");

System.out.println(

"Total " + formatter.format(totalCandy + totalCookie + totalIceCream + totalTaxCandy + totalTaxCookie));

System.out.println("CANDY [" + candiesCount + "] Cost: " + formatter.format(totalCandy) + " Tax: "

+ formatter.format(totalTaxCandy));

System.out.println("COOKIES [" + cookiesCount + "] Cost: " + formatter.format(totalCookie) + " Tax: "

+ formatter.format(totalTaxCookie));

System.out.println("ICECREAM [" + iceCreamCount + "] Cost: " + formatter.format(totalIceCream));

System.out.println("------------------------------------------------");

System.out.println("SubTotals [" + (candiesCount + iceCreamCount + cookiesCount) + "] "

+ formatter.format(totalCandy + totalCookie + totalIceCream) + " "

+ formatter.format(totalTaxCandy + totalTaxCookie));

System.out.println("================================================");

System.out.println(

"Total " + formatter.format(totalCandy + totalCookie + totalIceCream + totalTaxCandy + totalTaxCookie));

System.out.print("CANDY [" + candiesCount + "] Cost: " + formatter.format(totalCandy) + " Tax: "

+ formatter.format(totalTaxCandy) + " ");

System.out.print("COOKIES [" + cookiesCount + "] Cost: " + formatter.format(totalCookie) + " Tax: "

+ formatter.format(totalTaxCookie) + " ");

System.out.print("ICECREAM [" + iceCreamCount + "] Cost: " + formatter.format(totalIceCream) + " ");

System.out.print("------------------------------------------------ ");

System.out.print("SubTotals [" + (candiesCount + iceCreamCount + cookiesCount) + "] "

+ formatter.format(totalCandy + totalCookie + totalIceCream) + " "

+ formatter.format(totalTaxCandy + totalTaxCookie + " "));

System.out.print("================================================ ");

System.out.print("Total "

+ formatter.format(totalCandy + totalCookie + totalIceCream + totalTaxCandy + totalTaxCookie + " "));

System.out.println("Successfully receipt stored. ");

System.out.close();

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!