|
I have been playing with this code for two days and can't get it to what I want. I have made changes and got it to compile, but when I run it now it tells me I have a no such method error. Here is what I have now.
public class Product
{
private int itemNumber; // declare variable for item number
private String productName; // declare variable for product name
private int stockUnits; // declare variable for number of units in stock
private double unitPrice; // declare variable for unit price of each product
public double totalValue;
// Four argument constructor
public Product( int item, String name, int units, double price )
{
itemNumber = 0;
productName = name;
stockUnits = 0;
unitPrice = 0;
} // End four argument constructor
public void setItemNumber( int item ) // Set item number
{
itemNumber = item;
} // end set item number
public int getItemNumber() // return item number
{
return itemNumber;
} // end return item number
public void setProductName( String name ) // set product name
{
productName = name;
} // end set product name
public String getProductName() // return product name
{
return productName;
} // end return product name
public void setStockUnits( int units ) // set units in stock
{
stockUnits = units;
} // end set units in stock
public int getStockUnits() // return units in stock
{
return stockUnits;
} // end return units in stock
public void setUnitPrice( double price ) // set unit price
{
unitPrice = price;
} // end set unit price
public double getUnitPrice() // return unit price
{
return unitPrice;
} // end return unit price
public double totalValue() // calculate total value
{
totalValue = stockUnits * unitPrice;
return totalValue;
} // end method to calculate total value
public void displayInventory()
{
System.out.println( "Item # Name Stock Unit Price Total Value" );
System.out.printf( "%d", itemNumber, "%S", productName, "%d", stockUnits);
System.out.printf( "%.2f", unitPrice, "%.2f", totalValue );
}
} // end class product
public class InventoryPart1
{
public int item;
public String name;
public int units;
public double price;
public void main( String args[] )
{
Product product1 = new Product( item, name, units, price );
item = 001;
name = "Dream Catcher";
units = 25;
price = 7.99;
product1.setItemNumber( item );
product1.setProductName( name );
product1.setStockUnits( units );
product1.setUnitPrice( price );
}
}
|