Inventory Program Part 2

Help with Inventory program 2

Page 1 of 1

2 Replies - 7976 Views - Last Post: 18 December 2008 - 09:20 PM Rate Topic: -----

#1 edgeofthorns  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 18-December 08

Inventory Program Part 2

Posted 18 December 2008 - 08:02 PM

Here is the assignment for part 2
1. CheckPoint: Inventory Program Part 2
Resource: Java: How to Program
Due Date: Day 4 [Individual] forum
Modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price of each unit, and the value of the inventory of that product. In addition, the output should display the value of the entire inventory.
Create a method to calculate the value of the entire inventory.
Create another method to sort the array items by the name of the product.
Post as an attachment




Here is what I have so far. The second part is giving me problems as I am having alot of confusion in my understanding of java so far.

// Week 6 Checkpoint 1 - Inventory2
// Richard Fondy
// IT/215 - Java Programming
// Inventory2.java
// December 18th, 2008




import java.util.Arrays;


public class Inventory2 {

	public static void main(String[] args) {

		DVD dvd;

		System.out.println("\nCheckPoint: Inventory Part 1\n");

		dvd = new DVD(01, "No Country For Old Men", 1, 10.49f);
		System.out.println(dvd);

		dvd = new DVD(14, "Cloverfield", 2, 9.99f);
		System.out.println(dvd);

		dvd = new DVD(36, "Spiderman 3", 10, 6.89f);
		System.out.println(dvd);

		dvd = new DVD(04, "The Mist", 6, 5.75f);
		System.out.println(dvd);

		System.out.println("\nEnd of Inventory, have a good day!\n");
	} //end main

} // end class Inventory2




class DVD {
	private int dvdItem;
	private String dvdTitle;
	private int dvdStock;
	private double dvdPrice;

	public DVD(int item, String title, int stock, double price) {
		dvdItem  = item;
		dvdTitle = title;
		dvdStock = stock;
		dvdPrice = price;
	} //end four-argument constructor

	// set DVD Item
	public void setDvdItem(int item) {
		dvdItem = item;
	} //end method  set Dvd Item

	//return DVD Item
	public int getDvdItem() {
		return dvdItem;
	} //end method get Dvd Item

	//set DVD Title
	public void setDvdTitle(String title) {
		dvdTitle = title;
	} //end method set Dvd Title

	//return Dvd Title
	public String getDvdTitle() {
		return dvdTitle;
	} //end method get Dvd Title

	public void setDvdStock(int stock) {
		dvdStock = stock;
	} //end method set Dvd Stock

	//return dvd Stock
	public int getDvdStock() {
		return dvdStock;
	} //end method get Dvd Stock

	public void setDvdPrice(double price) {
		dvdPrice = price;
	} //end method setdvdPrice

	//return DVD Price
	public double getDvdPrice() {
		return dvdPrice;
	} //end  method get Dvd Price

	//calculate inventory value
	public double value() {
		return dvdPrice * dvdStock;
	} //end method value

	public String toString() {
		return String.format("item=%03d   title=%-23s   units=%3d   price= $%6.2f   value= $%7.2f",
							 dvdItem, dvdTitle, dvdStock, dvdPrice, value());
	}

} //end class DVD


class Inventory {
	private DVD[] dvds;			///the DVD collection
	private int numDVDs;		///the number of DVDs in the collection

	Inventory() {
		dvds = new DVD[100];
		numDVDs = 0;
	}

	  // Add DVD into Inventory end
	  public void addToInventory(DVD dvd) 
   {
	  // create a new array of DVDs that can hold one more than the current array of DVDs						 DVD[ ] newdvds = new DVD [numDVDs () + 1];
  
  
	

	 //Adds up the total value
		public double value() 
		double total = 0;

		for (int i = 0; i < numDVDs(); i++){
			total = total + dvds[i].value();
		return total;
	}
	// add the new Product to the end of the new array
	   new_dvds [numdvds ()] = new_DVD;

	// replace the old inventory with the new one
	dvds = newdvds;
  }
  // return the DVDs at the location index in the inventory 
   public DVD getDVD (int index)
  {  
		return dvds [index];
  }
  // return the number of Products in the inventory
	public int getSize()
  {
		return dvds.length;
  }
   // go through all the DVDs in the inventory, and add up their value.
	public double getTotalValueOfAllInventory()
	{
		double tot = 0.00;
		
		for(int i = 0; i < numDVDs(); i++)
		{
			tot += inventory						[i].calculateValue();
		}
		return tot;
  }
  
  // sort the DVDs in the inventory by movie title 
	public void sortInventory() 
	{
		Arrays.sort(inventory, 0, getSize()); 
	}


} //end class Inventory




Is This A Good Question/Topic? 0
  • +

Replies To: Inventory Program Part 2

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Inventory Program Part 2

Posted 18 December 2008 - 08:13 PM

You must have a co-student just a topic away
check it
Was This Post Helpful? 0
  • +
  • -

#3 edgeofthorns  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 18-December 08

Re: Inventory Program Part 2

Posted 18 December 2008 - 09:20 PM

View Postpbl, on 18 Dec, 2008 - 07:13 PM, said:

You must have a co-student just a topic away
check it


Ok I have checked the other post and got alot of help. I have alot of errors still. 26 to be exact.

Please help

// Week 6 Checkpoint 1 - Inventory2
// Richard Fondy
// IT/215 - Java Programming
// Inventory2.java
// December 18th, 2008




import java.util.Arrays;


public class Inventory2 {

	public static void main(String[] args) {

		DVD dvd;

		System.out.println("\nCheckPoint: Inventory Part 

1\n");

		dvd = new DVD(01, "No Country For Old Men", 1, 

10.49f);
		System.out.println(dvd);

		dvd = new DVD(14, "Cloverfield", 2, 9.99f);
		System.out.println(dvd);

		dvd = new DVD(36, "Spiderman 3", 10, 6.89f);
		System.out.println(dvd);

		dvd = new DVD(04, "The Mist", 6, 5.75f);
		System.out.println(dvd);

		System.out.println("\nEnd of Inventory, have a 

good day!\n");
	} //end main

} // end class Inventory2




class DVD {
	private int dvdItem;
	private String dvdTitle;
	private int dvdStock;
	private double dvdPrice;

	public DVD(int item, String title, int stock, double 

price) {
		dvdItem  = item;
		dvdTitle = title;
		dvdStock = stock;
		dvdPrice = price;
	} //end four-argument constructor

	// set DVD Item
	public void setDvdItem(int item) {
		dvdItem = item;
	} //end method  set Dvd Item

	//return DVD Item
	public int getDvdItem() {
		return dvdItem;
	} //end method get Dvd Item

	//set DVD Title
	public void setDvdTitle(String title) {
		dvdTitle = title;
	} //end method set Dvd Title

	//return Dvd Title
	public String getDvdTitle() {
		return dvdTitle;
	} //end method get Dvd Title

	public void setDvdStock(int stock) {
		dvdStock = stock;
	} //end method set Dvd Stock

	//return dvd Stock
	public int getDvdStock() {
		return dvdStock;
	} //end method get Dvd Stock

	public void setDvdPrice(double price) {
		dvdPrice = price;
	} //end method setdvdPrice

	//return DVD Price
	public double getDvdPrice() {
		return dvdPrice;
	} //end  method get Dvd Price

	//calculate inventory value
	public double value() {
		return dvdPrice * dvdStock;
	} //end method value

	public String toString() {
		return String.format("item=%03d   title=%-23s   

units=%3d   price= $%6.2f   value= $%7.2f",
							 dvdItem, dvdTitle, dvdStock, 

dvdPrice, value());
	}

} //end class DVD


class Inventory {

		Inventory() {
		DVD dvds[] = new DVD[4];
   

		dvds[0] = new DVD(0, "Cloverfield",2, 9.99);
		dvds[1] = new DVD(1, "No Country For Old Men",1, 

10.49);
		dvds[2] = new DVD(2, "Spiderman 3",10, 6.89);
		dvds[3] = new DVD(3, "The Mist",6, 5.75);

   }

	  // Add DVD into Inventory end
	  public void addToInventory(DVD dvd){
	  dvds[Dvd.length] = Dvd;
	  ++Dvd.length;
	  }
	

	 //Adds up the total value
		public double value(){
		double total = 0;
		for (int i = 0; i < Dvd.length(); i++)
			total = total + Dvds[i].value();
		return total;
	
			System.out.println("dvdItem:	 " + Dvds

[i].getDvdItem());
			System.out.println("dvdName:	   " + Dvds

[i].getDvdName());
			System.out.println("dvdInventory:   " + Dvds

[i].getDvdInventory());
			System.out.println("dvdPrice:	  " + Dvds

[i].getDvdPrice());
			System.out.println("Item Value: " + Dvds

[i].getDvdInventory() * Dvds[i].getdvdPrice());




		
   
  }
  // return the DVDs at the location index in the 

inventory 
   public DVD getDVD (int index){  
		return Dvds [index];
  }
  // return the number of Products in the inventory
	public int getSize()
  {
		return DVD.length;
  }
   // go through all the DVDs in the inventory, and add 

up their value.
	public double Value(){
	double tot = 0.00;
	for(int i = 0; i < DVD.length(); i++)
		tot += dvds[i].value();					   

  return tot;
  }
  
  // sort the DVDs in the inventory by movie title 
	public void sort() 
	{
		Arrays.sort(Dvds, 0, getSize()); 
	}


} //end class Inventory



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1