Question: Can someone finish the code for stage 2 Stage 1 package dessertshop; mport java.text.NumberFormat; import java.util.Locale; abstract class DessertItem { protected String name; public DessertItem()
Can someone finish the code for stage 2
Stage 1
package dessertshop;
mport java.text.NumberFormat; import java.util.Locale;
abstract class DessertItem { protected String name; public DessertItem() { this.name = ""; } public DessertItem(String name) { this.name = name; } public final String getName() { return name; } public abstract double getCost(); }
class Candy extends DessertItem { private double weight; private double pricePerPound;
public Candy(String name,double unitWeight,double unitPrice) { super(name); this.weight = unitWeight; this.pricePerPound = unitPrice; } @Override public double getCost() { return(weight*pricePerPound); } public String toString() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return (name + "\t\t\t" + formatter.format(this.getCost()) +" \t" + this.weight +" lbs @ "+ formatter.format(this.pricePerPound)); } }
class Cookie extends DessertItem { private int numCookies; private double pricePerDozen;
public Cookie(String name,int numCookies,double pricePerDozen) { super(name); this.numCookies = numCookies; this.pricePerDozen = pricePerDozen; } @Override public double getCost() { return(numCookies * pricePerDozen); } public String toString() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return (name + "\t\t\t" + formatter.format(this.getCost()) +" \t" + this.numCookies +" Cookies @ "+ formatter.format(this.pricePerDozen))+" per Dozen"; } }
class IceCream extends DessertItem { private int numScoops; private double pricePerScoop;
public IceCream(String name,int numScoops,double pricePerScoop) { super(name); this.numScoops = numScoops; this.pricePerScoop = pricePerScoop; } @Override public double getCost() { return(numScoops * pricePerScoop); } public String toString() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return (name + "\t\t\t" + formatter.format(this.getCost())); } }
class DessertShop { public static void main (String[] args) { Candy item1 = new Candy("Peanut Butter Fudge",2.25,3.99); Cookie item2 = new Cookie("Oatmeal Raisins Cookies",4,3.99); IceCream item3 = new IceCream("Vanilla Ice Cream",2,1.05); System.out.println(item1); System.out.println(item2); System.out.println(item3); } }
Stage 2: Enhance the classes defined in Stage 1 to develop a Cash Register Application
The objective of the second stage is to develop a Cash Register application which will utilize the classes developed in Stage 1.
Stage 2: Task(s)
The programmer will use and extend the classes and methods developed in Stage 1 to develop a Cash Register type of application. 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 of Candy, Number of Pounds and Price per Pound
COOKIE
Prompt for Name of Cookie, Number of Cookies and Price per Dozen
ICE CREAM
Prompt for Name of Ice Cream, Number of Scoops, Price per Scoop and Topping Price
The application should be called DessertShop, which will prompt the user for items to purchase one at a time.
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 three arrays for each DessertType, which can store up to 5 items each.
Each derived class will contain a static variable which will store the total DessertType cost and total DessertType 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. As each DessertType item is added, the cost and tax should be added to the individual DessertType static values.
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. As each DessertType item is added, the cost and tax should be added to the DessertItem static values.
Upon entering all items, the application should print out a summary of all purchased DessertItems, along with the count, the cost and tax. (See Sample Output)
Stage 2: Sample Output
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
