I have hit a stone wall this week. I have tried numeous methods to get a functioning array into this code, and get the code to call for a total value. Now I have changed code around untik I no longer have compile errors, but now all of my values are null. Please help me out, as I don't know of anything else to do but to start over at an empty line 1. This project is for an inventory program to document CDs (number, title, quantity, price, value), and be able to return the value of the collection. The following is my code as it stands now.
public class mediaInventory
{
public static void main(String args [])
{
CD mycd[];
CD myCd = new CD(1, "Alice in Chains", 4, 14.99);
System.out.println( myCd );
myCd = new CD( 2, "Black Label Society", 8, 17.99 );
System.out.println( myCd );
myCd = new CD( 3, "Bonoroo", 2, 21.99 );
System.out.println( myCd );
myCd = new CD( 4, "Dio", 5, 14.99 );
System.out.println( myCd );
myCd = new CD( 5, "Eric Clapton", 11, 12.99 );
System.out.println( myCd );
myCd = new CD( 6, "Led Zeppelin", 9, 16.99 );
System.out.println( myCd );
myCd = new CD( 7, "Monte Montgomery", 3, 18.99 );
System.out.println( myCd );
myCd = new CD( 8, "Primus", 5, 14.99 );
System.out.println( myCd );
myCd = new CD( 9, "SRV", 5, 17.99 );
System.out.println( myCd );
myCd = new CD( 10, "Tool", 4, 13.00 );
System.out.println( myCd );
} //end main
} // end class mediaInventory1
class CD
{
private int itemNum;
private String cdTitle;
private int cdUnits;
private double cdPrice;
public CD( int item, String title, int units, double price )
{
itemNum = item;
String CdTitle = title;
int CdUnits = units;
double CdPrice = price;
} //end four argument constructor
public void setItemNum( int item ) // set CD Item
{
itemNum = item;
} //end method set Cd Item
public int getItemNum() //return CD Item
{
return itemNum;
} //end method get Cd Item
public void setCdTitle( String title ) //set CD Title
{
String CdTitle = title;
} //end method set Cd Title
public String getCdTitle() //return Cd Title
{
String CdTitle = cdTitle;
return CdTitle;
} //end method get Cd Title
public void setCdUnits( int units )
{
cdUnits = units;
} //end method set Cd Units
public int getCdUnits() //return Cd Units
{
return cdUnits;
} //end method get Cd Units
public void setCdPrice(double price)
{
cdPrice = price;
} //end method setcdPrice
public double getCdPrice() //return Cd Price
{
return cdPrice;
} //end method get Cd Price
public double value() //calculate inventory value
{
return cdPrice * cdUnits;
} //end method value
public String toString()
{
return String.format( "Item No: %3d Title: %-12s Quantity: %d Price:$%.2f Value: $%.2f",
itemNum, cdTitle, cdUnits, cdPrice, value() );
}
}
Any help & guidance is greatly appreciated.