inv prg pt3

Not sure what I'm missing

Page 1 of 1

1 Replies - 778 Views - Last Post: 01 September 2008 - 04:46 PM Rate Topic: -----

#1 Behumat   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 28-August 08

inv prg pt3

Post icon  Posted 31 August 2008 - 05:45 PM

Here's the project: 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. I seem to be messing up the super commands, and I'm not sure what is wrong.
package arrays;
public class Main
{
   // main method starts program
   public static void main( String args[] )
   {
	  double total = 0.0;
	  Product inventory[]; // Array variable
	  
	  inventory = new Product[ 5 ]; // Size of the array
	  
	  // create Product object
	  inventory [ 0 ] = new Product( "Norton Antivirus", 1, 16, 50.00 );
	  inventory [ 1 ] = new Product( "Solaris Linux", 2, 12, 100.00 );
	  inventory [ 2 ] = new Product( "Windows XP", 3, 4, 60.00 );
	  inventory [ 3 ] = new Product( "Eclipse", 4, 4, 150.00 );
	  inventory [ 4 ] = new Product( "Microsoft Office Suite", 5, 7, 60.00 );
	  for (int counter = 0; counter < 5; counter++)
	  {

		 System.out.printf(inventory[counter].toString());

	  } // end for
	  
	  total = (inventory[ 0 ].getValueOfStock() +
			   inventory[ 1 ].getValueOfStock() +
			   inventory[ 2 ].getValueOfStock() +
			   inventory[ 3 ].getValueOfStock() +
			   inventory[ 4 ].getValueOfStock());
	  System.out.printf( "The total value of the inventory is: $%.2f\n\n", total );
   } // end main
	 
} // end class main


package arrays;

/**
 *
 * @author 
 */

/*
 * This product class lists the name, product amount, and price
*/

public class Product
{
   // declare variables
   private String productName; // name of the software
   private int itemNumber; // item number
   private int units; // item quantity
   private double priceUnit; // item price
	 
   // Constructor to store the info
   public Product( String theproduct, int number, int unit, double price )
	  { 
		 // Variable Default Values
		 productName = theproduct; // initializes item
		 itemNumber = number; // initializes itemNumber
		 units = unit; // initializes number of Units
		 priceUnit = price; // initializes pricePerUnit
	  } // End Constructor.
	   
	 Product inventory[] = new Product [ 3 ];

	 // Store the software
	 public void setProduct ( String theproductIn )
	 {
		productName = theproductIn;
	 } // End store software
   
	 // Store item Number
	 public void setItemNumber ( int itemNumberIn )
	 {
		itemNumber = ( ( itemNumberIn > 0 ) ? itemNumberIn :0 );
	 } // End store of item Number
  
	 //Store units
	 public void setunits ( int unitsIn )
	 {
		units = ( ( unitsIn > 0 )?unitsIn:0 );
	 } // End store of units
	 
	 //Store price per unit
	 public void setPriceUnit ( double priceUnitIn )
	 {
		priceUnit = ( ( priceUnitIn > 0.0 )?priceUnitIn:0.0 );
	 } // End store of price per unit

	 // method getproductName
	 public String getproductName()
	 {
		return ( productName );
	 } // End method getproductName

	 // method getItemNumber
	 public int getItemNumber()
	 {
		return ( itemNumber );
	 } // End method getItemNumber
   
	 // method getUnits
	 public int getUnits()
	 {
		return ( units ); 
	 } // End method getUnits

	 public double priceUnit()
	 {
		return ( priceUnit );
	 } // End method getPriceUnit
   
	 // method getValueOfStock
	 public double getValueOfStock()
	 {
		return ( units * priceUnit );
	 } // End method getValueOfStock	

	 // method getInventoryValue
	 public double getInventoryValue ( Product inventory[])
	 {
		double value = 0.0;
		for ( Product d: inventory )
		{
		   value += d.getValueOfStock();
		} // End for

		return (value);

	 } // End method getInventoryValue
	 
	 //toString Method
	 public String toString ()	//Returns a formatted String for output purposes	 
	 {
				 
		String formatString	= "Product Name				  : %s\n";
		formatString		  += "Item Number				: %d\n";
		formatString		  += "Software Units			  : %d\n";
		formatString		  += "Price Per Unit			 : $%.2f\n";
		formatString		  += "Value of Stock			 : $%.2f\n\n";
	  
		return (String.format ( formatString, productName, itemNumber, units, priceUnit, getValueOfStock()) ); 
				  
	 } // End toString method
	
}//End Product

package arrays;

/**
 *
 * @author 
 */
public class Inv extends Product 
{
		private double reStockingFee;
 
	 public Inv(double priceUnit, double reStockingFee) {
 
		 // calling the parent class 
		super(priceUnit);
		// setting the cost of restocking the item
	   this.reStockingFee = reStockingFee;
	 }
 
	 // Returns the price of a program
	// This is calculated by adding the cost of restocking it onto the actual price
	 public double getPriceUnit() {
 
		 // Calling the parent class's getPrice method
		// and adding the cost of restocking to it
		 return super.getPriceUnit() + reStockingFee;
	 }
	 
	 public String toString() {
	 
	return new StringBuffer().append("Price: " + super.getPriceUnit()).append(" With RestockingFee: " + getPriceUnit()).toString();
	 }
	 
}




Is This A Good Question/Topic? 0
  • +

Replies To: inv prg pt3

#2 pbl   User is offline

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

Reputation: 8379
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: inv prg pt3

Posted 01 September 2008 - 04:46 PM

Your class Inv which extends Product calls

	// calling the parent class 
	super(priceUnit);



Product does not have a constructor that receives a double as parameter... the only constructor of product is

// Constructor to store the info
public Product( String theproduct, int number, int unit, double price )

Inv also calls

// Calling the parent class's getPrice method
// and adding the cost of restocking to it
return super.getPriceUnit() + reStockingFee;


the class Product does not have a method called getPriceUnit()
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1