Inventory Program Part 3 (yes another one) PLEASE HELP!!!
Sorry,
I've gone through all the forms looking for other issues "newbies" like myself have had with the Inventory Program we are learning in school.
Unforetunately, I'm still having trouble. If anyone can help point out where I've gone wrong in my code and point me in the write direction to fix it I would appreciate the assist. I only have one more day until I have to turn this in.
FYI - unlike some, I'm not looking for anyone to do my homework for me and I'll continue to work on this myself after posting this. Thanks!
Assignment Description:
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.
Modify the output to display this additional feature you have chosen and the restocking fee.
I have three classes in my program. DVDInfo3.java and DVD_Directors.java compile as shown below without any problems. InventoryProgram3.java does not. I am getting the following error:
E:\Java\JavaApplication7\src\InventoryProgram3.java:27: cannot find symbol
symbol : constructor DVD_Directors(java.lang.String,java.lang.String,int,int,double)
location: class DVD_Directors
inventory [ 0 ] = new DVD_Directors( "Titanic", "James Cameron", 10001, 5, 9.95 );
I have gone over my code, other's code posted in these forums, and my text book for the last 4 days and can't figure out why it doesn't see my DVD_Directors constructor.
I've included my current source code for this assignment below and the source code for my previous assignment "Inventory Program Part 2" below that for reference. Part 2 compiled and worked fine, so I'm not sure why this won't.
Inventory Program Part 3 - Source Code:
/*
* InventoryProgram3.java
*/
import java.util.Arrays;// program uses arrays for sorting
publicclass InventoryProgram3
{
// main method begins execution of Java program
publicstaticvoid main( String args[] )
{
double total = 0.0;
DVD_Directors inventory[];// Array variable
inventory =new DVD_Directors[ 5 ];// Size of the array
// create DVD_Directors object
inventory [ 0 ] =new DVD_Directors("Titanic","James Cameron", 10001, 5, 9.95 );
inventory [ 1 ] =new DVD_Directors("TheGoonies","Richard Donner", 10002, 2, 4.95 );
inventory [ 2 ] =new DVD_Directors("AsGoodAsItGets","James L. Brooks", 10003, 3, 9.95 );
inventory [ 3 ] =new DVD_Directors("StarGate","Roland Emmerich", 10004, 1, 9.95 );
inventory [ 4 ] =new DVD_Directors("StarWars","George Lucas", 10005, 5, 14.95 );
Arrays.sort ( inventory );
for (int counter = 0; counter < 5; counter++)
{
System.out.printf(inventory[counter].toString());
}// end for
DVD_Directors.getInventoryValue( inventory );// passes inventory array reference
}// end main
}// end class InventoryProgram3
/*
* DVDInfo3.java
*/
publicclass DVDInfo3implements Comparable
{
// declare variables
protected String title;// title of DVD
protected String director;// director of movie
protectedint diskNumber;
protectedint stockedUnits;
protecteddouble pricePerUnit;
// Constructor to store the DVD info
public DVDInfo3( )
{
// Variable Default Values
title ="";// initializes title
director ="";// initializes director
diskNumber = 0;// initializes diskNumber
stockedUnits = 0;// initializes stockedUnits
pricePerUnit = 0.0;// initializes pricePerUnit
}// End Constructor
DVDInfo3 inventory[] =new DVDInfo3 [ 5 ];
// Inventory constructor
public DVDInfo3 ( String titleIn, String directorIn,int diskNumberIn,int stockedUnitsIn,double pricePerUnitInDollars )
{
// set title
setTitle ( titleIn );
// set director
setDirector ( directorIn );
// set disk number
setDiskNumber ( diskNumberIn );
// set stocked units
setStockedUnits ( stockedUnitsIn );
// set price per unit in dollars
setPricePerUnit ( pricePerUnitInDollars );
}// end Inventory constructor
// Store DVD Title
publicvoid setTitle ( String titleIn )
{
title = titleIn;
}// End store of DVD Title
// store DVD Director
publicvoid setDirector ( String directorIn )
{
director = directorIn;
}// End method setDirector
// Store DVD Disk Number
publicvoid setDiskNumber (int diskNumberIn )
{
diskNumber = ( ( diskNumberIn > 0 ) ? diskNumberIn :0 );
}// End store of DVD Disk Number
//Store stocked units
publicvoid setStockedUnits (int stockedUnitsIn )
{
stockedUnits = ( ( stockedUnitsIn > 0 )?stockedUnitsIn:0 );
}// End store of stocked units
//Store price per unit
publicvoid setPricePerUnit (double pricePerUnitIn )
{
pricePerUnit = ( ( pricePerUnitIn > 0.0 )?pricePerUnitIn:0.0 );
}// End store of price per unit
// method getTitle
public String getTitle()
{
return ( title );
}// End method getTitle
// method getDirector
public String getDirector()
{
return ( director );
}// End method getDirector
// method getDiskNumber
publicint getDiskNumber()
{
return ( diskNumber );
}// End method getDiskNumber
// method getStockedUnits
publicint getStockedUnits()
{
return ( stockedUnits );
}// End method getStockedUnits
publicdouble getPricePerUnit()
{
return ( pricePerUnit );
}// End method getPricePerUnit
// method getValueOfStock
publicdouble getValueOfStock()
{
return ( stockedUnits * pricePerUnit );
}// End method getValueOfStock
// method getInventoryValue
publicstaticdouble getInventoryValue ( DVDInfo3 inventory3[] )
{
double total = 0.0;
total = (inventory3[ 0 ].getValueOfStock() +
inventory3[ 1 ].getValueOfStock() +
inventory3[ 2 ].getValueOfStock() +
inventory3[ 3 ].getValueOfStock() +
inventory3[ 4 ].getValueOfStock());
System.out.printf("The total value of this entire inventory is: $%.2f\n\n", total );
return ( total );
}// End method getInventoryValue
publicint compareTo ( Object o )
{
String sort2 = ( ( DVDInfo3 ) o ).title.toUpperCase();
String sort1 = title.toUpperCase();
return ( sort1.compareTo ( sort2 ) );
}
//toString Method
public String toString ()//Returns a formatted String for output purposes
{
String formatString="\nDVD Title: %s\n";
formatString +="Disk Number: %d\n";
formatString +="Stocked Units : %d\n";
formatString +="Price Per Unit : $%.2f\n";
formatString +="Value of Stock : $%.2f\n\n";
return (String.format ( formatString, title, diskNumber, stockedUnits, pricePerUnit, getValueOfStock()) );
}// End toString method
}//End class DVDInfo3
/*
* DVD_Directors.java
*/
publicclass DVD_Directorsextends DVDInfo3// the DVD_Directors Subclass
{
// declare variables
privatedouble baseStockPrice;
privatedouble baseInventoryValue;
privatedouble restockFee;
// Constructor to store the new DVD info
public DVD_Directors( )
{
// variable default values
director ="";
restockFee = 0.05;
}
DVD_Directors inventory[] =new DVD_Directors [ 5 ];
// DVD_Directors Inventory Constructor
public DVD_Directors (String titleIn, String directorIn,int diskNumberIn,int stockedUnitsIn,double pricePerUnitInDollars,
double getPricePerUnitInDollars,double getInventoryValue,double restockFee)
{
// explicit call to superclass DVDInfo3
super (titleIn, directorIn, diskNumberIn, stockedUnitsIn, pricePerUnitInDollars);
setBaseStockPrice(getPricePerUnitInDollars);
setBaseInventoryValue(getInventoryValue);
this.restockFee = restockFee;
}// End DVD_Directors Constructor
// set base stock price
publicvoid setBaseStockPrice(double getPricePerUnitInDollars)
{
baseStockPrice = ( getPricePerUnitInDollars < 0.0 ) ? 0.0 : getPricePerUnitInDollars;
}// end method setBaseStockPrice
// return base stock price
publicdouble getBaseStockPrice()
{
return baseStockPrice;
}// end method getBaseStockPrice
// calculate and return the price per unit, plus the restocking fee
publicdouble getBaseStockPricePlusFee()
{
return baseStockPrice + (baseStockPrice * restockFee);
}// End method getBaseStockPricePlusFee
// set base inventory value
publicvoid setBaseInventoryValue(double getInventoryValue)
{
baseInventoryValue = ( getInventoryValue < 0.0 ) ? 0.0 : getInventoryValue;
}// end method setBaseInventoryValue
// return base inventory value
publicdouble getBaseInventoryValue()
{
return baseInventoryValue;
}// end method getBaseInventoryValue
// calculate and return the value of the inventory, plus the restocking fee
publicdouble getValueOfStockPlusFee()
{
return baseInventoryValue + (baseInventoryValue * restockFee);
}// End method getValueOfStockPlusFee
//toString Method
public String toString ()//Returns a formatted String for output purposes
{
String formatString="\nDVD Title : %s\n";
formatString +="Director: %s\n";
formatString +="Disk Number: %d\n";
formatString +="Stocked Units : %d\n";
formatString +="Price Per Unit : $%.2f\n";
formatString +="Price Per Unit /w Restock Fee: $%.2f\n";
formatString +="Value of Stock : $%.2f\n";
formatString +="Value of Stock w/ Restock Fee: $%.2f\n\n";
return (String.format ( formatString, title, director, diskNumber, stockedUnits, pricePerUnit, getBaseStockPricePlusFee(), getValueOfStockPlusFee()) );
}// End toString method
}// End class DVD_Directors
Inventory Program Part 2 - Source Code:
/*
* InventoryProgram2.java
*/
import java.util.Scanner;// program uses Scanner
publicclass InventoryProgram2
{
// main method beigns execution of Java program
publicstaticvoid main( String args[] )
{
double total = 0.0;
DVDInfo2 inventory[];// Array variable
inventory =new DVDInfo2[ 5 ];// Size of the array
// create DVDInfo2 object
inventory [ 0 ] =new DVDInfo2("Titanic", 10001, 5, 9.95 );
inventory [ 1 ] =new DVDInfo2("TheGoonies", 10002, 2, 4.95 );
inventory [ 2 ] =new DVDInfo2("AsGoodAsItGets", 10003, 3, 9.95 );
inventory [ 3 ] =new DVDInfo2("StarGate", 10004, 1, 9.95 );
inventory [ 4 ] =new DVDInfo2("StarWars", 10005, 5, 14.95 );
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 InventoryProgram2
/*
* DVDInfo2.java
*/
publicclass DVDInfo2
{
// declare variables
private String title;// title of DVD
privateint diskNumber;
privateint stockedUnits;
privatedouble pricePerUnit;
// Constructor to store the DVD info
public DVDInfo2( String name,int number,int unit,double price )
{
// Variable Default Values
title = name;// initializes title
diskNumber = number;// initializes diskNumber
stockedUnits = unit;// initializes stockedUnits
pricePerUnit = price;// initializes pricePerUnit
}// End Constructor.
DVDInfo2 inventory[] =new DVDInfo2 [ 5 ];
// Store DVD Title
publicvoid setTitle ( String titleIn )
{
title = titleIn;
}// End store of DVD Title
// Store DVD Disk Number
publicvoid setDiskNumber (int diskNumberIn )
{
diskNumber = ( ( diskNumberIn > 0 ) ? diskNumberIn :0 );
}// End store of DVD Disk Number
//Store stocked units
publicvoid setStockedUnits (int stockedUnitsIn )
{
stockedUnits = ( ( stockedUnitsIn > 0 )?stockedUnitsIn:0 );
}// End store of stocked units
//Store price per unit
publicvoid setPricePerUnit (double pricePerUnitIn )
{
pricePerUnit = ( ( pricePerUnitIn > 0.0 )?pricePerUnitIn:0.0 );
}// End store of price per unit
// method getTitle
public String getTitle()
{
return ( title );
}// End method getTitle
// method getDiskNumber
publicint getDiskNumber()
{
return ( diskNumber );
}// End method getDiskNumber
// method getStockedUnits
publicint getStockedUnits()
{
return ( stockedUnits );
}// End method getStockedUnits
publicdouble getPricePerUnit()
{
return ( pricePerUnit );
}// End method getPricePerUnit
// method getValueOfStock
publicdouble getValueOfStock()
{
return ( stockedUnits * pricePerUnit );
}// End method getValueOfStock
// method getInventoryValue
publicdouble getInventoryValue ( DVDInfo2 inventory[])
{
double value = 0.0;
for ( DVDInfo2 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="DVD Title: %s\n";
formatString +="Disk Number: %d\n";
formatString +="Stocked Units : %d\n";
formatString +="Price Per Unit : $%.2f\n";
formatString +="Value of Stock : $%.2f\n\n";
return (String.format ( formatString, title, diskNumber, stockedUnits, pricePerUnit, getValueOfStock()) );
}// End toString method
}//End DVDInfo2
Again, I appreciate any advice or help you might be able to provide. Thanks!

