Question: This programming assignment will the lab from Module #12, DessertShop to develop a Cash Register type of application. The purpose of this assignment is to

This programming assignment will the lab from Module #12, DessertShop to develop a Cash Register type of application. The purpose of this assignment is to use those programming concepts that have been developed recently.

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 Sundaes. 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 DessertItems, along with the count, the cost and tax. (See 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.

Programming Code Use in Lab 12:

package dessertshop;

import java.text.NumberFormat;

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 ); }

@Override public String toString() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return( name + "\t\t\t" + formatter.format( this.getCost()) + " \t" + this.weight + " lbs @ " + formatter.format( this.pricePerPound )); } } //Implementing class Cookie class Cookie extends DessertItem { //Private Instance Variables private int numCookies; private double pricePerDozen; //Constructor public Cookie( String name, int noCookies, double price ) { super( name ); this.numCookies = noCookies; this.pricePerDozen = price; } @Override public double getCost() { return( numCookies * (pricePerDozen/12.0) ); } @Override 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 "); } }

//Implementing class IceCream class IceCream extends DessertItem { //Private instance variables private int numScoops; private double pricePerScoop;

//Constructor public IceCream( String name, int noScoops, double price ) { super( name ); this.numScoops = noScoops; this.pricePerScoop = price; } @Override public double getCost() { return( numScoops * pricePerScoop ); } @Override public String toString() { NumberFormat formatter = NumberFormat.getCurrencyInstance(); return( name + "\t\t\t" + formatter.format( this.getCost()) + " \t" + this.numScoops + " Scoops @ " + formatter.format( this.pricePerScoop ) + " per Scoop "); } }

public class DessertShop { public static void main( String[] args ) { Candy item1 = new Candy( "Peanut 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 ); System.out.println( item1 ); System.out.println( item2 ); System.out.println( item3 ); } }

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!