Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Stage 3: Prompt the user for a receipt file name, write the contents of the receipt to the text file. The objective of this third

Stage 3: Prompt the user for a receipt file name, write the contents of the receipt to the text file. The objective of this third stage is to save the receipt information to a text file. Stage 3: Task(s) The objective of this third stage is to enhance the application developed in stage 2 to prompt for a filename to store the receipt information. Upon entering the receipt, the receipt contents developed in stage 2 will be output to the text file. The application should create a NoItemsEnteredException. The application should create a static method called itemsEntered which returns the total number of items purchased. If there are no items, the method should throw the NoItemsEnteredException. Assignment Evaluation Your assignment will be graded based upon all tasks being performed and handed in with all required documentation. Description Points Definition of the abstract DessertItem superclass 10 points Proper implementation of static variables for storing superclass cost and tax, as well as each individual derived cost and tax 10 points Definition of enumerated DessertType and use of switch statement to determine actions required 5 points Use of Arrays for storing up to 5 items of the four different DessertTypes. 5 points Definition of the Candy derived class 5 points Definition of the Cookie derived class 5 points Definition of the IceCream derived class 5 points Proper output of itemized purchases 5 points Integration of ItemsEntered method 5 points Proper implementation and use of NoItemsEnteredException 5 points Properly saving receipt information to Text file 10 points Proper Header and Source Code Documentation [Each class must contain proper documentation throughout both the class definitions and the application]

here is my code

package desertshop;

import java.util.Scanner;

import java.text.NumberFormat;

enum DesertType {

CANDY , COOKIE ,ICECREAM ;

}

/**

*

* @author wesley v

*/

public class DesertShop {

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 );*/

DesertType 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;

DesertShop desertshop = new DesertShop();

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 = DesertType.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();

desertshop.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();

desertshop.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();

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

break;

}

} while(true);

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

totalCookie+=(desertshop.cookies[i].getCost());

totalTaxCookie+=desertshop.cookies[i].getTax();

System.out.println(desertshop.cookies[i].toString());

}

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

totalCandy+=(desertshop.candies[i].getCost());

totalTaxCandy+=desertshop.candies[i].getTax();

System.out.println(desertshop.candies[i].toString());

}

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

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

System.out.println(desertshop.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));

}

}

import java.text.NumberFormat;

/**

*

* @author wesley v

*/

class Candy extends DesertItem {

private double weight;

private double priceperPound;

public static final double tax = .07;

public Candy (String name, double unitWeight,double unitPrice){

super(name);

this.weight = unitWeight;

this.priceperPound= unitPrice;

}

@Override

public double getCost(){

return (weight * priceperPound);

}

public double getTax(){

return getCost()* tax;

}

public String toString (){

NumberFormat formatter = NumberFormat.getCurrencyInstance();

double cost = this.getCost();

return (name + "\t\t\t" + formatter.format(cost) + " [Tax:"+formatter.format(cost * tax)+ "]"+" \t" +

this.weight +" lbs @ "+ formatter.format(this.priceperPound));

}

class Cookie extends DesertItem {

private int NumberOfCookies;

private double priceperDozen;

public static final double tax = .07;

public static float cost;

public Cookie (String name, int numberUnits,double unitPrice){

super(name);

this.NumberOfCookies = numberUnits;

this.priceperDozen= unitPrice;

}

@Override

public double getCost(){

return( NumberOfCookies * priceperDozen/12);

}

public double getTax(){

return getCost()* tax;

}

public String toString (){

NumberFormat formatter = NumberFormat.getCurrencyInstance();

double cost = this.getCost();

return (name + "\t\t\t" + formatter.format(cost) + " [Tax:"+formatter.format(cost * tax) +"]" +" \t" +

this.NumberOfCookies +" Cookies @ "+ formatter.format(this.priceperDozen))+" per Dozen";

}

}

abstract class DesertItem {

protected String name;

public DesertItem (){

this.name = "";

}

public DesertItem (String name ){

this.name = name;

}

public final String getName(){

return name;

}

public abstract double getCost();

}

class IceCream extends DesertItem {

private int numberOfSccops;

private double pricePerScoop;

private double toppingPrice;

public IceCream (String name, int numberUnits ,double unitPrice, double toppings){

super(name);

this.numberOfSccops = numberUnits;

this.pricePerScoop = unitPrice;

this.toppingPrice = toppings;

}

@Override

public double getCost(){

return( numberOfSccops * pricePerScoop + toppingPrice);

}

public String toString (){

NumberFormat formatter = NumberFormat.getCurrencyInstance();

return (name +"\t\t\t" + formatter.format(this.getCost())+ " \t" +

this.numberOfSccops+ "scoops@ " + formatter.format(this.pricePerScoop)

+ " + "+ formatter.format(this.toppingPrice) );

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 2 Lnai 6322

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215882X, 978-3642158827

More Books

Students also viewed these Databases questions

Question

Distinguish between filtering and interpreting. (Objective 2)

Answered: 1 week ago