2 Replies - 616 Views - Last Post: 08 October 2012 - 02:38 PM Rate Topic: -----

#1 oneorderja  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 17-September 12

Want to modify this CashRegister program?

Posted 08 October 2012 - 10:52 AM

I want to modify the Cash Resigter Code below to create a file containing a sales receipt. The program should ask the user for the quantity of items being purchased, and then generate a file with contents below:

SALE RECEIPT
Unit Price : $10.00
Quantity: 5
Subtotal: $50.00
Sales Tax: $3.00
Total: $53.00

Here is my code:

public class CashRegister
	{
	    private RetailItem retailItem;
	    private int quantityItems;
	    private final double SALES_TAX = .06;
	    private int subTotal;
	 	private double price;



	    public CashRegister ()
	    {
	        quantityItems = 0;
	        subTotal = 0;
	    }


	   public CashRegister(RetailItem retailObject, int quantity)
	   {
	      price = retailObject.getPrice();

	      quantityItems = quantity;

	      subTotal = sub;

	   }



	    public RetailItem getRetailItem()
	    {

	        return new RetailItem();
	    }

	    public double getSubTotal()
	    {
	        return quantityItems * retailItem.getPrice();
	    }

	    public double getTax()
	    {
	        return SALES_TAX;
	    }


	    public double getTotal()
	    {
	        return subTotal + SALES_TAX;
	    }

	    public String toString()
	    {
	    	return " Unit Price:" + getPrice() + "Quantity:" + quantityItems + "SubTotal" + getSubTotal
	    		     + " Sales Tax" + getTax() + " Total" + getTotal();
 	    }
	   }
AND: 
import java.util.Scanner;

public class SalesReceipt
{
	public static void main (String [] args)
	{

		CashRegister yourRegister = new CashRegister(null, 5);


		Scanner keyboard = new Scanner(System.in);

		System.out.println(" How much quantity is being purchased: " );
			quantityItems = keyboard.nextInt();


	}
}




Is This A Good Question/Topic? 0
  • +

Replies To: Want to modify this CashRegister program?

#2 jdavi134  Icon User is offline

  • D.I.C Head

Reputation: 42
  • View blog
  • Posts: 225
  • Joined: 26-October 11

Re: Want to modify this CashRegister program?

Posted 08 October 2012 - 11:04 AM

So what's the problem?
Was This Post Helpful? 0
  • +
  • -

#3 DoinWork  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 69
  • Joined: 26-October 11

Re: Want to modify this CashRegister program?

Posted 08 October 2012 - 02:38 PM

Seems like you just need to open up a file stream with your output file, write it and don't forget to close it.

Here is one simple example if you want to go that route, if not there are plenty of other ways found by a simple google search. Writing to File
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1