i am a beginning student in java programming and I have to make an inventory application. I was able to compile my class but I cant get the sub class to compile and execute. can someone tell what to do.
public class Cars1
{
private String productName;
private String itemNumber;
private int numberOfUnits;
private double pricePerUnit;
public Cars1( String productName, String itemNumber, int numberOfUnits,
double pricePerUnit )
{
productName = productName;
itemNumber = itemNumber;
numberOfUnits = numberOfUnits;
pricePerUnit = pricePerUnit;
}
public void setProductName( String productName )
{
productName = productName;
}
public String getProductName()
{
return productName;
}
public void setItemNumber( String itemNumber )
{
itemNumber = itemNumber;
}
public String getItemNumber()
{
return itemNumber;
}
public void setNumberOfUnits( int numberOfUnits )
{
numberOfUnits = numberOfUnits;
}
public int getNumberOfUnits()
{
return numberOfUnits;
}
public void setPricePerUnit( double price )
{
pricePerUnit = ( price < 0.0 ) ? 0.0 : price;
}
public double getPricePerUnit()
{
return pricePerUnit;
}
public String toString()
{
return String.format( "%s %s\n%s: %s\n%s: %s\n%s: %.2f\n" ,
getProductName(), getItemNumber(), getNumberOfUnits(), getPricePerUnit() );
}
}
that is my super class or parent
public class CarInventory extends Cars1
{
public static void main( String args )
{
CarInventory cars1 = new CarInventory(
"Mercedes Benz", "1089", "2", 60000 );
system.out.printf( "%s %s\n", "Product name is",
cars1.getProductName() );
System.out.printf( "%s %s\n", "Item number is",
cars1.getItemNumber() );
System.out.printf( "%s %s\n", "Number of Units",
cars1.getNumberOfUnits() );
System.out.printf( "%s %.2f\n", "Price per unit",
cars1.getPricePerUnit() );
}
}
this is my subclass, what is wrong here ,please help me someone.