5 Replies - 1600 Views - Last Post: 18 July 2008 - 12:24 PM Rate Topic: -----

#1 twgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 08

Help With Inventory Program part 2

Posted 17 July 2008 - 10:37 AM

My assignment says: 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.
I truely do not know if I am re-writing all my program or I am just adding to it? And either way I do not know know where to start. Here is what I have:

package javaapplication25;


	public class FGInventoryProgram1{  
	  
		FGInventoryProgram1() {	// constructor  
			  
		   DVD[] dvd =  new DVD[4];  
	  
			dvd[0] = new DVD("How to Loose a Guy in 10 days", 4, 19.99, 685.0);  
		   dvd[1] = new DVD("Cyote Ugly", 8, 19.98, 565.0);  
			dvd[2] = new DVD("Legally Blonde", 10, 19.99,785.0);  
		   dvd[3] = new DVD("Sweet Home Alabama",8,18.56,578.0);		   for(int i = 0; i < 4; i++) {  
			   System.out.println(dvd[i]);  
			   System.out.println("Product Title is " + dvd[i].getDvdTitle());  
			   System.out.println("The number of units in stock is" + dvd[i].getDvdStock());  
			   System.out.println("The price of each DVD is" + dvd[i].getDvdPrice());  
			   System.out.println("The item number is " + dvd[i].getDvdItem());  
			   System.out.println("The value of the inventory is" + dvd[i].value());  
		   }  
	 
	   }  
	 
	   public static void main(String args []) {  
	 
		   new FGInventoryProgram1();  
	 
	   } //end method main  
	 
	 
	 
	   class DVD {  
	 
		   private String dvdTitle;  
		   private double dvdStock;  
		   private double dvdPrice;  
		   private double dvdItem;  
	 
		   DVD(String title, double stock, double price, double item) {  
			   dvdTitle = title;  
			   dvdStock = stock;  
			   dvdPrice = price;  
			   dvdItem  = item;  
		   } //end four-argument constructor  
	 
		   public void setDvdTitle(String title) {  
			   dvdTitle = title;  
		   } //end method  setDvdTitle  
	 
		   //return DVD Title  
		   public String getDvdTitle() {  
			   return dvdTitle;  
		   } //end method getDvdTitle  
	 
		   //set DVD Stock  
		   public void setDvdStock(double stock) {  
			   dvdStock = stock;  
		   } //end method setDvdStock  
	 
		   //return DvdStock  
		   public double getDvdStock() {  
			   return dvdStock;  
		   } //end method get Dvdstock  
  
		   
  
		   public void setDvdPrice(double price) {  
  
			   dvdPrice = price;  
		   } //end method setDvdPrice  
	 
		   //return dvdPrice  
		   public double getDvdPrice() {  
			   return dvdPrice;  
		   } //end method get Dvd Price  
	 
		   public void setDvdItem(double item) {  
			   dvdItem = item;  
		   } //end method setdvdItem  
	 
		   //return DVD item  
		   public double getDvdItem() {  
			   return dvdItem;  
		   } //end  method getDvdItem  
	 
		   //calculate inventory value  
		   public double value() {  
			   return dvdPrice * dvdStock;  
		   } //end method value  
	 
	   } //end class DVD  
   }  t
  



This post has been edited by twgood: 17 July 2008 - 11:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Help With Inventory Program part 2

#2 abgorn  Icon User is offline

  • sudo apt-get install brain
  • member icon

Reputation: 30
  • View blog
  • Posts: 1,410
  • Joined: 05-June 08

Re: Help With Inventory Program part 2

Posted 17 July 2008 - 02:17 PM

Is there a question you want answered?
Was This Post Helpful? 0
  • +
  • -

#3 twgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 08

Re: Help With Inventory Program part 2

Posted 17 July 2008 - 05:55 PM

I truely do not know if I am re-writing all my program or I am just adding to it? And either way I do not know know where to start.
Was This Post Helpful? 0
  • +
  • -

#4 twgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 08

Re: Help With Inventory Program part 2

Posted 17 July 2008 - 06:23 PM

View Posttwgood, on 17 Jul, 2008 - 05:55 PM, said:

I truely do not know if I am re-writing all my program or I am just adding to it? And either way I do not know know where to start.

Ok, here is what I now have so far, it has an error though!
package javaapplication27;



public class FGInventory2{
	
}
		class Product implements Comparable
{
		private long itemNumber;	// class variable that stores the item number
		private String itemName;	// class variable that stores the item name
		private long invQuantity;   // class variable that stores the quantity in stock
		private double itemPrice;   // class variable that stores the item price
			
			public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
				{
					itemNumber = number;
					itemName = name;
					invQuantity = quantity;
					itemPrice = price;
				}
				
			public void setItemNumber(long number)  // Method to set the item number
				{
					this.itemNumber = number;
				}
				
			public long getItemNumber()  // Method to get the item number
				{
					return itemNumber;
				}
				
			public void setItemName(String name)  // Method to set the item name
				{
					this.itemName = name;
				}
				
			public String getItemName()  // Method to get the item name
				{
					return itemName;
				}
				
			public void setinvQuantity(long quantity)  // Method to set the quantity in stock
				{
					invQuantity = quantity;
				}
				
			public long getInvQuantity()  // Method to get the quantity in stock
				{
					return invQuantity;
				}
				
			public void setItemPrice(double price)  // Method to set the item price
				{
					this.itemPrice = price;
				}
				
			public double getItemPrice()  // Method to get the item price
				{
					return itemPrice;
				}
				
			public double calculateInventoryValue()  // Method to calculate the value of the inventory
				{
					return itemPrice * invQuantity;
				}
			
			public int compareTo(Object o)
				{
					Product p = null;
						try
							{
								p = (Product) o;
							}
						
						catch (ClassCastException cE)
							{
								cE.printStackTrace();
							}
						
						return itemName.compareTo(p.getItemName());
				}
 
			public String toString()
				{
					return "Item #: " + itemNumber + "\nName: " + itemName + "\nQuantity: " + invQuantity + "\nPrice: $" + itemPrice + "\nValue: $" + calculateInventoryValue();
				}
}  //end class Product



		
public class FGInventory2

	{
		Product[] supplies;
		
		public static void main(String[] args)
			{
				Inventory inventory = new Inventory();
				inventory.addProduct(new Product(685, "How to Losse a Guy in 10 days", 4, 19.99));
				inventory.addProduct(new Product(565, "Cyote Ugly", 8, 19.98));
				inventory.addProduct(new Product(785, "Legally Blonde", 10, 19.99));
				inventory.addProduct(new Product(578, "Sweet Home Alabama", 8, 18.56));
 
				System.out.println(); // blank line
				System.out.println("Welcome to DVD Inventory 1.0"); //display header
				inventory.sortByName(); //sort list by name
				System.out.println(); // blank line
				inventory.showInventory(); //display inventory
 
				double total = inventory.calculateTotalInventory();
				System.out.println("Total Value is: $" + total);
 
			}
 
		public void sortByName()
			{
				for (int i = 1; i < supplies.length; i++)
					{
						int j;
						Product val = supplies[i];
						for (j = i - 1; j > -1; j--)
							{
								Product temp = supplies[j];
								if (temp.compareTo(val) <= 0)
									{
									break;
									}
								supplies[j + 1] = temp;
							}
						supplies[j + 1] = val;
					}
			}
 
		public String toString() //creates a String representation of the array of products
			{
				String s = "";
				for (Product p : supplies)
					{
						s = s + p.toString();
						s = s + "\n\n";
					}
				return s;
			}
 
		public void addProduct(Product p1) //Increases the size of the array
			{
				if (supplies == null)
					{
						supplies = new Product[0];
					}
				Product[] p = supplies; //Copy all products into p first
				Product[] temp = new Product[p.length + 1]; //create bigger array
				for (int i = 0; i < p.length; i++)
					{
						temp[i] = p[i];
					}
				temp[(temp.length - 1)] = p1; //add the new product at the last position
				supplies = temp;
			}
 
		public double calculateTotalInventory() //sorting the array using Bubble Sort
			{
				double total = 0.0;
				for (int i = 0; i < supplies.length; i++)
					{
						total = total + supplies[i].calculateInventoryValue();
					}
				return total;
			}
 
		public void showInventory()
		{
			System.out.println(toString()); //call our toString method
		}
		
	} //end Class FGInventory2

Here is the code I am getting:
init:
deps-jar:
Compiling 1 source file to C:\NetBeansProjects\SCHOOL1\JavaApplication27\build\classes
C:\NetBeansProjects\SCHOOL1\JavaApplication27\src\javaapplication27\FGInventory2.java:93: duplicate class: javaapplication27.FGInventory2
public class FGInventory2
1 error
BUILD FAILED (total time: 0 seconds)
Was This Post Helpful? 0
  • +
  • -

#5 JeroenFM  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 18
  • View blog
  • Posts: 195
  • Joined: 30-June 08

Re: Help With Inventory Program part 2

Posted 18 July 2008 - 01:25 AM

You are declaring FGInventory2 twice, remove the top one (the empty one)
Was This Post Helpful? 0
  • +
  • -

#6 twgood  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 14-May 08

Re: Help With Inventory Program part 2

Posted 18 July 2008 - 12:24 PM

View PostJeroenFM, on 18 Jul, 2008 - 01:25 AM, said:

You are declaring FGInventory2 twice, remove the top one (the empty one)

Thank you so much!!! Now to start part 3.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1