1,105,332 Community Members

Sales Receipt Program from Cash Register Program???

Member Avatar
oneoderja
Newbie Poster
11 posts since Oct 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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



        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;
        }
    }
Member Avatar
NormR1
Posting Sage
7,723 posts since Jun 2010
Reputation Points: 563 [?]
Q&As Helped to Solve: 793 [?]
Skill Endorsements: 16 [?]
Team Colleague
 
0
 

What are you having problems with converting the posted code?
Do you have any specific questions?
Two things I see that you need:
Ask user for data. Scanner class can help
write data to file. See the PrintWriter class

Member Avatar
stultuske
Posting Expert
5,290 posts since Jan 2007
Reputation Points: 935 [?]
Q&As Helped to Solve: 774 [?]
Skill Endorsements: 35 [?]
Featured
 
0
 
  1. remove the first constructor
  2. complete the second constructor to set all the values (since you can all deduct them from the two you pass on)
  3. add a toString method
  4. in your main method:
    a. instantiate a RetailItem
    b. call the constructor of CashRegister with the RetailItem and the number of items
    c. print the CashRegister
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article