3 Replies - 770 Views - Last Post: 20 July 2008 - 02:37 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 3

Post icon  Posted 19 July 2008 - 01:33 PM

I am not getting error messages, but it is not doing what I ant it to do..here is the assignment:
Modify the Inventory Program by creating a subclass of the product class that uses one
additional unique feature of the product you chose (for the DVDs subclass, you could use
movie title, for example). In the subclass, create a method to calculate the value of the
inventory of a product with the same name as the method previously created for the
product class. The subclass method should also add a 5% restocking fee to the value of
the inventory of that product.

 
package javaapplication29;


		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
		private int itemYear;	  // class variable that stores the item year
			
			public Product(long number, String name, long quantity, double price, int year) // Constructor for the Supplies class
				{
					itemNumber = number;
					itemName = name;
					invQuantity = quantity;
					itemPrice = price;
					itemYear = year; 
					
				}
				
			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 setItemYear(int year)  // Method to get the item year
				{
					this. itemYear= year;
				}
			
				public int getYear()  // Method to get the item year
				{
					return itemYear;
				}
			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 getItemValue() {
		return getItemValue() * 1.05; 
		
			
		}
			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 FGInventory3

	{
		Product[] supplies;
		
		public static void main(String[] args)
				
			{
				FGInventory3 inventory = new FGInventory3();
				inventory.addProduct(new Product(685, "How to Losse a Guy in 10 days", 4, 19.99,2004));
				inventory.addProduct(new Product(565, "Cyote Ugly", 8, 19.98, 1997));
				inventory.addProduct(new Product(785, "Legally Blonde", 10, 19.99, 1998));
				inventory.addProduct(new Product(578, "Sweet Home Alabama", 8, 18.56, 2005));

				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 FGInventory3



Is This A Good Question/Topic? 0
  • +

Replies To: Help with Inventory Program Part 3

#2 Onker  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 51
  • Joined: 15-July 08

Re: Help with Inventory Program Part 3

Posted 19 July 2008 - 01:53 PM

When I run your code, I get the following output.

Item #: 565
Name:[b]Cyote[/b] Ugly
Quantity: 8
Price: $19.98
Value: $159.84

Item #: 685
Name: How to [b]Losse[/b] a Guy in 10 days
Quantity: 4
Price: $19.99
Value: $79.96

Item #: 785
Name: Legally Blonde
Quantity: 10
Price: $19.99
Value: [b]$199.89999999999998[/b]

Item #: 578
Name: Sweet Home Alabama
Quantity: 8
Price: $18.56
Value: $148.48


Total Value is: $588.18



I see that the restock fee isn't posting like you said, and a couple other minor issues. Which I bold faced above. Nitpicky stuff, but *shrug* I'd rather you submit something which is perfect rather than not. I'll see what I can unravel on the other part though.

This post has been edited by Onker: 19 July 2008 - 01:55 PM

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 3

Posted 19 July 2008 - 08:33 PM

Thanks, I just for the life of me can not figure out what the problem is.
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 3

Posted 20 July 2008 - 02:37 PM

Please Help, I have to get this done before Wed. so I can start the next phase before I have surgery on Friday, so I do not get behind in class.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1