Inventory Program Help

Need help adding total inventory value to GUI

Page 1 of 1

3 Replies - 637 Views - Last Post: 23 February 2009 - 08:23 AM Rate Topic: -----

#1 TWhite64  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-February 09

Inventory Program Help

Posted 22 February 2009 - 09:00 PM

Any help with this would be greatly appreciated. I am new to programming so the more help and experience the better.

public class Product {

	private String itemNumber; // item number
	private String productName; //cd name
	private int units; //units in stock
	public double price; //cd price
	private double fee; //cd restocking fee

	// constructor
	public Product(String itemNumber, String productName, int units, double price, double fee){
		this.itemNumber = itemNumber;
		this.productName = productName;
		this.units = units;
		this.price = price;
		this.fee = fee;
	}


	// returns inventory value
		public double value() {
			return units*price;
		}

		// get, set, and return
		public String getItemNumber() {
			return itemNumber;
		}

		public void setItemNumber(String itemNumber) {
			this.itemNumber = itemNumber;
		}

		public String getProductName() {
			return productName;
		}

		public void setProductName(String productName) {
			this.productName = productName;
		}

		public int getUnits() {
			return units;
		}

		public void setUnits(int units) {
			this.units = units;
		}

		public double getPrice() {
			return price;
		}

		public void setPrice(double price) {
			this.price = price;
		}
		public double getFee() {
			return fee;
		}
		public void setFee(double fee){
		this.fee = fee;
		}


	public static double TotalInventoryValue(Product [] inv)
	{
		double tiv = 0.0;

		for(int i = 0; i < inv.length; i++)
		{
		tiv += inv[i].value();
		}
		return tiv;
	}

	public String toString()
	{
	return "Item Number: " + itemNumber
	+ "\nProduct Name: " + productName
	+ "\nUnits: " +units
	+ "\nPrice: " + String.format ("$%.2f", price)
	+ "\nValue: " + String.format ("$%.2f", value())
	+ "\nRestocking Fee: " + String.format ("$%.2f", fee);
	}
} // end class Product



// begin Supplier
class Supplier extends Product {

	String supplierName;
	double restockingFee;


	public void restockingFee  ( double restock)
	{
restockingFee = (price* .05);
}
public double getRestockingFee()
{
	return restockingFee;
}
	public Supplier(String supplierName, double restockingFee, String itemNumber, String productName, int units,
			double price, double fee) {
		super(itemNumber, productName, units, price, fee);
		this.supplierName = supplierName;
		this.restockingFee = restockingFee;
	}

	public double calculateInventory() // total inventory value including restocking fee
	{
		return  super.value() + (super.value() * restockingFee);
	}

	public String toString()
	{
		StringBuffer strbf = new StringBuffer("\nSupplier: ").append(supplierName).append("\n");
		strbf.append(super.toString());

		return strbf.toString();
	}

} // end class Supplier


// InventoryProgram4.java


import javax.swing.*;

public class InventoryProgram4{

	// main method begins execution of Java application
	public static void main(String args[]){

	double supplierName = .05;

		Supplier[] inventory = new Supplier[5]; //create array of DVD movies

		inventory[0] = new Supplier("Slingshot Media Group" ,supplierName, "11231","J. Flue" , 133, 16.99, 0.85);
		inventory[1] = new Supplier("T.H.I.S. Click Records" ,supplierName, "11232","K-Drama" , 125,  10.29, 0.51 );
		inventory[2] = new Supplier("OneRoute Entertainment",supplierName, "11233","D.M.A.U.B.;", 122,  11.50, 0.57);
		inventory[3] = new Supplier("F.I.C. Music",supplierName,"11234","Lesun" , 145, 15.00, 0.75);
		inventory[4] = new Supplier("Slingshot Media Group",supplierName,"11235","Street Pastor", 111, 12.00, 0.60);

		Supplier temp[] = new Supplier[1];

		//initialize and set parameters for JTextArea
	   JTextArea txt = new JTextArea(20,20);
	   txt.setEditable(false);

		// Sorting Inventory Information
		for(int j = 0; j < inventory.length - 1; j++)
		{
			for(int k = 0; k < inventory.length - 1; k++)
			{
				if(inventory[k].getProductName().compareToIgnoreCase(inventory[k+1].getProductName()) > 0)
				{
				temp[0] = inventory[k];
				inventory[k] = inventory[k+1];
				inventory[k+1] = temp[0];
				}
			}
		}

		// Print Inventory Information
		for(int j = 0; j < inventory.length; j++)
		{
			txt.append("Inventory Information:");
			txt.append("\n" +inventory[j].toString());
		}

		// create jframe
		JFrame frame = new JFrame ("Inventory Program");

	   frame.getContentPane().add(new JScrollPane(txt));
	   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	   frame.pack();
	   frame.setLocationRelativeTo(null);
	   frame.setVisible(true);

		// set window size
		frame.setSize(350,700);
		frame.setVisible(true);

		System.out.printf("\nTotal Inventory Value: $%.2f\n" , Product.TotalInventoryValue(inventory));
		return;

	}
} // End InventoryProgram4 Class


The code compiles and runs and everything is shown in the window except the total inventory value.
How can I add the total inventory value to my gui?

Thanks in advance for the help!

This post has been edited by TWhite64: 22 February 2009 - 09:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Program Help

#2 OrganizedChaos  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 153
  • Joined: 29-November 08

Re: Inventory Program Help

Posted 22 February 2009 - 09:31 PM

Just taking a stab at this. You have
Product.TotalInventoryValue(inventory)

Shouldn't this be something like
inventory[n].TotalInventoryValue(inventory)

...because Product is the actual class rather than an object of that class... I may be completely wrong, but I thought it was worth mentioning.
Was This Post Helpful? 0
  • +
  • -

#3 TWhite64  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 22-February 09

Re: Inventory Program Help

Posted 22 February 2009 - 09:36 PM

Thanks for the help. I was just working with the program and I figured out a way to add it:
txt.append(String.format ("\n\nTotal Inventory Value: $%.2f\n", Product.TotalInventoryValue(inventory)));

Thanks again OrganizedChaos; and sorry for wasting your time
Was This Post Helpful? 0
  • +
  • -

#4 OrganizedChaos  Icon User is offline

  • D.I.C Head

Reputation: 39
  • View blog
  • Posts: 153
  • Joined: 29-November 08

Re: Inventory Program Help

Posted 23 February 2009 - 08:23 AM

No problem n_n;;
And no worries, not a waste of time at all.
Glad you figured it out.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1