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

Below is what I have at the moment. Unsure exactly how to implement the question

ID: 3841451 • Letter: B

Question

Below is what I have at the moment. Unsure exactly how to implement the question(s) in the "Switch Statement." Unsure exactly what is even asking. Do I set the arrays in the individual cases? Any help would be appreciated. My apologies for the length.

This application will declare an enumerated type ‘DessertType’, which will be used in a switch statement to determine which action needs to be taken.

Depending on the DessertType, the program should prompt for specific details in order to calculate the price for each item.

CANDY

Prompt for Name, Number of Pounds, Price per Pound

COOKIE

Prompt for Name, Number of Cookies, Price per Dozen

ICE CREAM

Prompt for Name, Number of Scoops, Price per Scoop

SUNDAE

Prompt for Name, Number of Scoops, Price per Scoop, Number of Toppings and the Price per Topping

The application should be called ‘DessertShop’, which will prompt the user for items to purchase. This application will prompt the user for the name of the product. If no name is entered, the application will calculate the total cost of items entered.

The application will define four arrays for each DessertItem, which can store up to 10 items each.

Each derived class will contain a static variable which will store the total DessertItem cost and total DessertItem tax (if applicable) for that specific DessertType. The CANDY and COOKIE dessert types are taxable at 7%. The ICE CREAM and SUNDAY dessert types are non-taxable.

The DessertItem superclass will also contain a total cost and total tax static variable that will be shared between all items that were derived from that superclass.

Upon successfully entering an item, the total cost and total tax of that DessertItem will be updated, along with the total cost and total tax for all items. The application should check an item to determine if that item has already been entered, except for Sundae’s.   If the item has already been entered, the existing information should be updated to include the new items.

Upon entering all items, the application should print out a summary of the DessertItem’s, along with the count, the cost and tax. (See Sample Output)

Sample Output

CANDY        [2]       Cost:   $4.52    Tax: $0.32

COOKIES     [24]       Cost: $12.96    Tax: $0.91

ICE CREAM    [1]       Cost:   $3.99

SUNDAE       [4]       Cost:   $8.87

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

Subtotals   [31]              $30.34         $1.23

                             ========

Total                          $31.57

After the total has been displayed, the application will prompt the user to see if they would like to save the receipt to a file. If ‘yes’, the application should prompt the user for the file name they would like to write the receipt to. The application should then open a text file and output the receipt information to the output file.

public class DessertShopProject {
   
    enum DessertType { //DECLARE THE ENUMERATION
        CANDY,
        COOKIES,
        ICE_CREAM,
        SUNDAE
    }; //REMEMBER NOT LOCAL

        public static void main(String[] args) {
       
        ///////TEST//////
       
Candy item1 = new Candy("Peanut Butter Fudge", 1, .99);
Cookie item2 = new Cookie("Oatmeal Raisin Cookies", 4, 3.99);
IceCream item3 = new IceCream("Vanilla Ice Cream", 2, 1.05);
Sundae item4 = new Sundae("Bananna Split", 2, 1.05, 4, 2.00);

      System.out.println( item1 );
      System.out.println( item2 );
      System.out.println( item3 );
      System.out.println( item4 );
       
       
       
       
//        Scanner keyboard = new Scanner(System.in);
//       
//        String nameOfTheProduct;
//        int numberOfItems;
//       
//        //FOUR ARRAY(S) FOR EACH 'DESSERT_ITEM'....Store 10 items
//        int candyArray[] = new int[10];
//        int cookieArray[] = new int[10];
//        int iceCreamArray[] = new int[10];
//        int subdaeArray[] = new int[10];
//       
//        System.out.println("Please, enter the items you wish to purchase");
//        numberOfItems = keyboard.nextInt();
//        System.out.println("Now, please enter the name of the desired product");
//        nameOfTheProduct = keyboard.nextLine();
//       
//        //DECLARE A DESSERT_TYPE REFERENCE / ASSIGN NAME
//        DessertType dessertType = DessertType.valueOf(nameOfTheProduct);
//       
//        switch (dessertType) {
//            case CANDY:
//                candy.respectiveDessertTotalCost();
//                break;
//            case COOKIES:
//                cookie.respectiveDessertTotalCost();
//                break;
//            case ICE_CREAM:
//                iceCream.respectiveDessertTotalCost();
//                break;
//            case SUNDAE:
//                sundae.respectiveDessertTotalCost();
//                break;
//            default:
//                System.out.println("Sorry, you entered something incorrectly");
//                break;
//               
//        }//END SWITCH_STATEMENT
//       
    }//End Main()
}//End Desert Shope Class

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package dessertshopproject;

public abstract class DessertItem {

    protected String name;
    static double dessertItemCost;
    static double totalDessertItemTax;

    //DEFAULT CONSTRUCTOR
    public DessertItem() {
        this.name = "";
    }

    //CUSTOM CONSTRUCTOR
    public DessertItem(String name) {
        this.name = name;
    }

    //GET AND SET
    public String getName() {
        return name;
    }

    //TotalCost--Down The Line..."NO BODY"
    public abstract double respectiveDessertTotalCost();

}//END CLASS DESSERT_ITEM

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package dessertshopproject;

import java.text.NumberFormat;
public class Candy extends DessertItem {

    
    private double candyNumberOfLbs;
    private double candyPricePerLbs;
    //Each Derived Class will contain a static variable!! Cost/Tax
    static double totalCandyCost;
    static double totalCandyTax;

    //Custom Constructor
    public Candy(String name, double candyNumberOfLbs, double candyPricePerLbs) {
        super(name);
        this.candyNumberOfLbs = candyNumberOfLbs;
        this.candyPricePerLbs = candyPricePerLbs;
    }

    public double getCandyNumberOfLbs() {
        return candyNumberOfLbs;
    }

    public double getCandyPricePerLbs() {
        return candyPricePerLbs;
    }

        @Override
    public double respectiveDessertTotalCost() {
        double result;
        totalCandyCost = (candyNumberOfLbs * candyPricePerLbs);
        totalCandyTax = (totalCandyCost * 0.07);
        ///////////////////////////////////////
        result = totalCandyCost + totalCandyTax;
        return result;
    } //End Respective_Dessert_Total_Cost

    @Override
    public String toString() {
        NumberFormat formatter = NumberFormat.getCurrencyInstance();
        return (super.getName() + " Cost: " + formatter.format(this.respectiveDessertTotalCost())
                + " Tax: " + formatter.format(totalCandyTax));
    }

}// END CLASS CANDY

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package dessertshopproject;

import java.text.NumberFormat;
import java.util.Scanner;
public class Cookie extends DessertItem {

   
    private int numberOfCookies;
    private double cookiePricePerDozen;
    //Each Derived Class will contain a static variable!! Cost/Tax
    private static double totalCookieCost;
    private static double totalCookieTax;

    //CUSTOM CONSTRUCTOR
    public Cookie(String name, int numberOfCookies, double cookiePricePerDozen) {
        super(name);
        this.numberOfCookies = numberOfCookies;
        this.cookiePricePerDozen = cookiePricePerDozen;
    }

    public int getNumberOfCookies() {
        return numberOfCookies;
    }

    public double getCookiePricePerDozen() {
        return cookiePricePerDozen;
    }

    @Override
    public double respectiveDessertTotalCost() {
        double result;
        totalCookieCost = (numberOfCookies * (cookiePricePerDozen / 12));
        totalCookieTax = (totalCookieCost * 0.07);//------->Only CANDY/COOKIES
        ///////////////////////////////////////
        result = totalCookieCost + totalCookieTax;
        return result;
    }//End Respective_Dessert_Total_Cost

    @Override
    public String toString() {
        NumberFormat formatter = NumberFormat.getCurrencyInstance();
        return (super.getName() + " Cost: " + formatter.format(this.respectiveDessertTotalCost())
                + " Tax: " + formatter.format(totalCookieTax));
    }

}//End Class_Cookie

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package dessertshopproject;

import java.text.NumberFormat;

public class IceCream extends DessertItem {
    private int numberOfScoops;
    private double iceCreamPricePerScoop;
    //Each Derived Class will contain a static variable!! Cost/Tax-- Not ICE_CREAM/SUNDAYS
    private static double totalIceCreamCost;

    //CUSTOM CONSTRUCTOR
    public IceCream(String name, int numberOfScoops, double iceCreamPricePerScoop) {
        super(name);
        this.numberOfScoops = numberOfScoops;
        this.iceCreamPricePerScoop = iceCreamPricePerScoop;
    }

    public int getNumberOfScoops() {
        return numberOfScoops;
    }

    public double getIceCreamPricePerScoop() {
        return iceCreamPricePerScoop;
    }

    @Override
    public double respectiveDessertTotalCost() {
        double result;
        totalIceCreamCost = (numberOfScoops * iceCreamPricePerScoop);
        ///////////////////////////////////////
        result = totalIceCreamCost;
        return result;
    }//End Respective_Dessert_Total_Cost

    @Override
    public String toString() {

        NumberFormat formatter = NumberFormat.getCurrencyInstance();

        return (super.getName() + " " + "Cost: " + formatter.format(this.respectiveDessertTotalCost()) + " ");
    }

}//END ICE_CREAM CLASS

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

package dessertshopproject;

import java.text.NumberFormat;

public class Sundae extends DessertItem {
    private int sundaeNumberOfScoops;
    private double sundaePricePerScoop;
    private int sundaeNumberOfToppings;
    private double sundaePricePerTopping;
    //Each Derived Class will contain a static variable!! Cost/Tax-- Not ICE_CREAM/SUNDAYS
    private static double totalSundaeCost;

    public Sundae(String name, int sundaeNumberOfScoops, double sundaePricePerScoop,
            int sundaeNumberOfToppings, double sundaePricePerTopping) {
        super(name);
        this.sundaeNumberOfScoops = sundaeNumberOfScoops;
        this.sundaePricePerScoop = sundaePricePerScoop;
        this.sundaeNumberOfToppings = sundaeNumberOfToppings;
        this.sundaePricePerTopping = sundaePricePerTopping;
    }

    public int getSundaeNumberOfScoops() {
        return sundaeNumberOfScoops;
    }

    public double getSundaePricePerScoop() {
        return sundaePricePerScoop;
    }

    public int getSundaeNumberOfToppings() {
        return sundaeNumberOfToppings;
    }

    public double getSundaePricePerTopping() {
        return sundaePricePerTopping;
    }

    @Override
    public double respectiveDessertTotalCost() {
        double result;

        totalSundaeCost = ((sundaeNumberOfScoops * sundaePricePerScoop)
                + (sundaeNumberOfToppings * sundaePricePerTopping));
        ///////////////////////////////////////
        result = totalSundaeCost;
        return result;
    }//End Respective_Dessert_Total_Cost

    @Override
    public String toString() {

        NumberFormat formatter = NumberFormat.getCurrencyInstance();

        return (super.getName() + " " + "Cost: " + formatter.format(this.respectiveDessertTotalCost()) + " ");
    }

}//END SUNDAE CLASS

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Below is what I have at the moment. Unsure exactly how to implement the question(s) in the "Switch Statement." Unsure exactly what is even asking. Do I set the arrays in the individual cases? Any help would be appreciated. My apologies for the length.

This application will declare an enumerated type ‘DessertType’, which will be used in a switch statement to determine which action needs to be taken.

Depending on the DessertType, the program should prompt for specific details in order to calculate the price for each item.

CANDY

Prompt for Name, Number of Pounds, Price per Pound

COOKIE

Prompt for Name, Number of Cookies, Price per Dozen

ICE CREAM

Prompt for Name, Number of Scoops, Price per Scoop

SUNDAE

Prompt for Name, Number of Scoops, Price per Scoop, Number of Toppings and the Price per Topping

The application should be called ‘DessertShop’, which will prompt the user for items to purchase. This application will prompt the user for the name of the product. If no name is entered, the application will calculate the total cost of items entered.

The application will define four arrays for each DessertItem, which can store up to 10 items each.

Each derived class will contain a static variable which will store the total DessertItem cost and total DessertItem tax (if applicable) for that specific DessertType. The CANDY and COOKIE dessert types are taxable at 7%. The ICE CREAM and SUNDAY dessert types are non-taxable.

The DessertItem superclass will also contain a total cost and total tax static variable that will be shared between all items that were derived from that superclass.

Upon successfully entering an item, the total cost and total tax of that DessertItem will be updated, along with the total cost and total tax for all items. The application should check an item to determine if that item has already been entered, except for Sundae’s.   If the item has already been entered, the existing information should be updated to include the new items.

Upon entering all items, the application should print out a summary of the DessertItem’s, along with the count, the cost and tax. (See Sample Output)

Sample Output

CANDY        [2]       Cost:   $4.52    Tax: $0.32

COOKIES     [24]       Cost: $12.96    Tax: $0.91

ICE CREAM    [1]       Cost:   $3.99

SUNDAE       [4]       Cost:   $8.87

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

Subtotals   [31]              $30.34         $1.23

                             ========

Total                          $31.57

After the total has been displayed, the application will prompt the user to see if they would like to save the receipt to a file. If ‘yes’, the application should prompt the user for the file name they would like to write the receipt to. The application should then open a text file and output the receipt information to the output file.

Explanation / Answer

I've modified to my understanding. Switch statement is now working fine. You can to provide the name of the dessert item in uppercase

PROGRAM CODE:

import java.util.Scanner;

public class DessertShopProject {

enum DessertType { //DECLARE THE ENUMERATION
CANDY,
COOKIES,
ICE_CREAM,
SUNDAE
}; //REMEMBER NOT LOCAL
public static void main(String[] args) {

///////TEST//////

Candy candy = new Candy("Peanut Butter Fudge", 1, .99);
Cookie cookie = new Cookie("Oatmeal Raisin Cookies", 4, 3.99);
IceCream iceCream = new IceCream("Vanilla Ice Cream", 2, 1.05);
Sundae sundae = new Sundae("Bananna Split", 2, 1.05, 4, 2.00);
System.out.println( candy );
System.out.println( cookie );
System.out.println( iceCream );
System.out.println( sundae );




Scanner keyboard = new Scanner(System.in);

String nameOfTheProduct;
int numberOfItems;

//FOUR ARRAY(S) FOR EACH 'DESSERT_ITEM'....Store 10 items
Candy candyArray[] = new Candy[10];
Cookie cookieArray[] = new Cookie[10];
IceCream iceCreamArray[] = new IceCream[10];
Sundae subdaeArray[] = new Sundae[10];

System.out.println("Please, enter the items you wish to purchase");
numberOfItems = keyboard.nextInt();
System.out.println("Now, please enter the name of the desired product");
keyboard.nextLine(); // to handle the extra newline
nameOfTheProduct = keyboard.nextLine();

//DECLARE A DESSERT_TYPE REFERENCE / ASSIGN NAME
// upper case because our enums are of uppercase
DessertType dessertType = DessertType.valueOf(nameOfTheProduct.toUpperCase());

switch (dessertType) {
   case CANDY:
System.out.println(candy.respectiveDessertTotalCost());
break;
case COOKIES:
   System.out.println(cookie.respectiveDessertTotalCost());
break;
case ICE_CREAM:
   System.out.println(iceCream.respectiveDessertTotalCost());
break;
case SUNDAE:
   System.out.println(sundae.respectiveDessertTotalCost());
break;
default:
System.out.println("Sorry, you entered something incorrectly");
break;

}//END SWITCH_STATEMENT

}//End Main()
}//End Desert Shope Class

OUTPUT:

Peanut Butter Fudge       Cost: $1.06       Tax: $0.07
Oatmeal Raisin Cookies       Cost: $1.42       Tax: $0.09
Vanilla Ice Cream       Cost: $2.10  
Bananna Split           Cost: $10.10  
Please, enter the items you wish to purchase
1
Now, please enter the name of the desired product
CANDY
1.0593

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote