hello all,
I am trying to create a class for an inventory program that will store certain values like name, item number number of units and price. I have written a code but it is apparently not correct because I get several error messages. can you please look at what I have and help me with this problem thank you.
public class Cars
{
private String productName;
private String itemNumber;
private String numberOfUnits;
private double pricePerUnit;
public Cars( String product, String item, String number,
double price )
{
productName = product;
itemNumber = item;
numberOfUnits = number;
setPrice( price );
}
public void setProductName( String product )
{
productName = product;
}
public String getProductName()
{
return productName;
}
public void setItemNumber( String item )
{
itemNumber = item;
}
public String getItemNumber()
{
return itemNumber;
}
public void setNumberOfUnits( String number )
{
numberOfUnits = number;
}
public String getNumberOfUnits()
{
return numberOfUnits;
}
public void setPrice( double price )
{
price = ( price < 0.0 ) ? 0.0 : price;
}
public double getPrice()
{
return price;
}
public String toString()
{
return String.format( "%s: %s\n%s: %s\n%s: %s\n%s: %.2f",
"Cars", product,
"item number", item,
"number of units", number,
"price per unit", price );
}
} // end class Cars