I can't use a loop to do it. I will copy and paste what I have:
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
// Four argument constructor
public Product( int item, String name, int units, double price )
{
itemNumber = item;
productName = name;
stockUnits = units;
unitPrice = price;
} // 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 getExtendedPrice() // calculate extended price
{
return stockUnits * unitPrice;
} // end method to calculate extended price
} // end class product
public class InventoryPart1
{
public static void main( String args[] )
{
// print column headings
system.out.println( "Item # Item Name Units in Stock Unit Price Extended Price" );
// instantiate first item
Product dreamCatcher = new Product( "001", "Dream Catcher", "25", "7.99" );
system.out.printf( dreamCatcher.getItemNumber(), dreamCatcher.getProductName(),
dreamCatcher.getStockUnits(), dreamCatcher.getUnitPrice(), dreamCatcher.getExtendedPrice() );
}
}
I just kind of guessed at the Inventory class. I am not sure how to return the results and make the table look good. Thanks for the help!
|