4 Replies - 24494 Views - Last Post: 26 January 2010 - 01:34 PM Rate Topic: ***** 2 Votes

#1 haloegirl  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-August 07

Sales Receipt Program

Post icon  Posted 02 August 2007 - 12:20 PM

Ok i am working on an assignement that shows the user what inventory is in stock, units on hand, and price, then the user can pick and choose what items they would like to purchase and a sales reciept is produced.
This program requires 4 class programs and a main driver that brings it all together.

Iam currently working on the first 2 and have many errors. The first two classes are:
Retail Item Class
Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields:
description The description fields references a String object that holds a brief description of the item.
unitsOnHand The unitsOnHand field is an int variable that holds the number of units currently in inventory.
price The price field is a double that holds the item's retail price.

Store Inventory Class
Write a StoreInventory class that creates an object that holds all the items in a store's inventory. The StoreInventory class should provide for storage of RetailItem objects that constitute a store's stock inventory. The StoreInventory class should have the following methods:

The addToInventory method should take a RetailItem object and add it to the store's inventory.

The getTotalPriceOfInventory method should return the total amount of retail dollars that the entire inventory represents.

The getUnitsOnHand method should return an integer value of the number of units on hand of an item.

Sales Transaction Class
Write a SalesTransaction class that creates a sales receipt as a result of point of sale operation. The SalesTransaction class should have the following methods:

The createSalesReceipt method will create a sales receipt from the currentTransaction object which contains quantities, descriptions and totals for each item purchased.

The sales receipt should look like the following:

Store xyz Sales Receipt
Quantity Description Totals
1 Jacket @ $59.95 each $59.95
2 Shirt @ $24.95 each $49.90
Subtotal: $109.85
Sales Tax: $4.67
Total: $114.52
Point Of Sale Class
Write a PointOfSale class that can be used with the classes that you wrote above. The PointOfSale class should simulate a retail sales transaction. The class should have the following methods:

The showItemInventory method should display the contents of the store's inventory and display an index number representing each item. That number will be used by the sales clerk to "ring up" an item. Items with 0 units on hand should not be displayed.

The enterItemAndQuantity method should accept an index number from the showItemInventory listing and an integer representing the number of items to be purchased, and create a soldItem object.

The getSubtotal method should return the subtotal of the sale, which is the quantity multiplied by the price. This method must get the price from the RetailItem object that was retrieved from the StoreInventory object.

The getTax method should return the amount of sales tax on the purchase. The sales tax is 4.25% of a retail sale.

The getTotal method should return the total of the sale, which is the subtotal plus the sales tax.

Demonstrate the classes written above in a program that asks the user to choose one or more separate items from the description of the RetailItems, specifies the quantity of each item being purchased, and then displays the sale's subtotal, amount of sales tax and total ( see description of sales receipt)

This is what i have so far..... can someone please help me with this
, I would really appriciate it.

/**
 	This class hold data about itmes in a retail store.
 */
 
public class RetailItem 
{
	//declare variables
	private String description;
	private int unitsOnHand; 
	private double price;
	
	//RetailIem class constructor
	public RetailItem()
	{
		description = " ";
		unitsOnHand = 0;
		price = 0.00;
	}
	
   public RetailItem(String description, int unitsOnHand, double price)
	{
		setDescription(description);
		setUnitsOnHand(unitsOnHand);
		setPrice(price);
	}
	/* Method: setDescription 
	 	@param unitDescription The descriptions of the retail items.	 
	 */
	 public void setDescription(String unitDescription)
	 {
	 	description = unitDescription; 
	 }
	 public void setUnitsOnHand(int units)
	 {
	 	unitsOnHand = units;
	 }
	 
	 public void setPrice(double thePrice)
	 {
	 	price = thePrice; 
	 }
	 
	 public String getDescription()
	 {
	 	return description;
	 }
	 
	 public int getUnitsOnHand()
	 {
	 	return unitsOnHand;
	 }
	 
	 public double getPrice()
	 {
	 	return price;
	 }
	 
	 public String toString()
	 {
	 	return "Items Sold: "; 
	 }
	
}


/**
This class creates an object that holds all the items in the store's inventory.
*/


public class StoreInventory
{
public StoreInventory()
{
String addToInventory;
Double getTotalPrice;
int unitsOnHand;
RetailItem inventory[];

}

public String addToInventory()
{
addToInventory[1] = new RetailItem("Jacket");
addToInventory[2] = new RetailItem("Designer Jeans");
addToInventory[3] = new RetailItem("Shirt");
addToInventory[4] = new RetailItem("Silk Tie");

}
public double getTotalPriceOfInventory()
{
inventory[1] = new RetailItem("59.95");
inventory[2] = new RetailItem("34.95");
inventory[3] = new RetailItem("24.95");
inventory[4] = new RetailItem("12.95");
return (unitsOnHand * totalPriceOfInventory);
}

public int getUnitsOnHand()
{
unitsOnHand [1] = new RetailItem("12");
unitsOnHand [2] = new RetailItem("40");
unitsOnHand [3] = new RetailItem("20");
unitsOnHand [4] = new RetailItem("15");
}

}
[code]

Is This A Good Question/Topic? 0
  • +

Replies To: Sales Receipt Program

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4438
  • View blog
  • Posts: 12,309
  • Joined: 18-April 07

Re: Sales Receipt Program

Posted 02 August 2007 - 03:42 PM

Hi haloegirl,

Well you were definitely on the right track with your approach. Your RetailItem class is perfect. No changes needed there. However your store inventory class needed a major rework. The idea here is that you build a single object one at a time and then give it to the store inventory class to save it. You do all the building in the initialization of the object. That is why you created constructors. Here is a brief example...

RetailItem myitem = new RetailItem("jacket", 12, 59.95);



Then you give it to your storeinventory class as a parameter to the addToInventory() function. Then to get the totals you simply loop through your inventory adding them up as you go along. Here is the storeinventory class with comments to explain what I did. Now I wasn't sure you were allowed to use the ArrayList collection yet, so I wrote this with a general plain "RetailItem" array.

public class StoreInventory
{
	// Create our inventory array of 10 items
	// Ideally you want to use an arraylist collection to make add delete easier.

	RetailItem inventory[] = new RetailItem[10];

	// Pass an item to the function and add it to inventory
	public String addToInventory(RetailItem item)
	{
		for (int i = 0; i < inventory.length; i++) {
			// Look for empty spot and put the item there.
			if (inventory[i] == null) {
				inventory[i] = item;
								break;
						}
		}

		return "Done";   // Return a success message perhaps
	}

	// Loop through the items looking for items, add their price to the total
	// Then just return the total

	public double getTotalPriceOfInventory()
	{
		double totalprice = 0.0;
		for (RetailItem currentItem : inventory) {
			if (currentItem != null) {
				totalprice += currentItem.getPrice();
			}
		} 
		return totalprice;
	}

	// Like the total price, we do it again with units on hand.
	// Notice how I use the RetailItem class reference to get at its method

	public int getUnitsOnHand()
	{
		int unitsonHand = 0;
		for (RetailItem currentItem : inventory) {
			if (currentItem != null) {
				unitsonHand += currentItem.getUnitsOnHand();
			}
		} 
		return unitsonHand;
	}

}



Now in your tester program you are going to create some RetailItems and add each one to the instance of a StoreInventory. Then call the StoreInventory's methods to get totals. Here is a basic tester program.

public class tester {

	public static void main(String args[]) {
		StoreInventory inventory = new StoreInventory();

		RetailItem item = new RetailItem("jacket", 1, 23.00);

		inventory.addToInventory(item);

		Double total = inventory.getTotalPriceOfInventory();

		System.out.println(total.toString());
	}
}



Notice how I first declare an instance of the inventory item, then build a RetailItem, then add it to the inventory. I then ask the inventory to give me a total and print it to screen. Hopefully these examples will get you moving on the project and onto the receipt part.

Good luck
Was This Post Helpful? 1

#3 whteclipse03  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-August 07

Re: Sales Receipt Program

Posted 05 August 2007 - 08:58 PM

I think we might be working on the same project can you help

email is whteclipse03@hotmail.com
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4438
  • View blog
  • Posts: 12,309
  • Joined: 18-April 07

Re: Sales Receipt Program

Posted 06 August 2007 - 09:41 AM

If you need help from us, please ask your questions here so that other people can learn from the answers given. Most of us will not respond via email to questions asked here. We believe in the whole idea of sharing the knowledge so that others can learn.

So please feel free to ask whatever questions you like. :)
Was This Post Helpful? 0
  • +
  • -

#5 thubbe  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 21-December 07

Re: Sales Receipt Program

Posted 26 January 2010 - 01:34 PM

hi


i have tryed ur StoreInventory code which is a example but it have some error

StoreInventory.java:28: ';' expected.
for (RetailItem currentItem : inventory) {
^

StoreInventory.java:42: ';' expected.
for (RetailItem currentItem : inventory) {
^


2errors


Can u pls tell me what is this two error

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1