I have been beating my head against the walls about the all time favorite Cars Inventory program. I got Cars to compile but won't run due to a exception in thread "main"java.lang.NoSuchMethodError:main
and spent many hours....trying to eliminate error.
// Cars.java
//Car inventory program
public class Cars
{
private int itemNumber; // item number
private String itemName; // item name
private int itemTotal; // total of cars in stock
private double itemPrice; // price per car
private double totalInventory; // total of cars in inventory
// initialize constructor with four arguments
public Cars( int number, String name, int total, double price )
{
itemNumber = number;
itemName = name;
itemTotal = total;
itemPrice = price;
} // end of constructor with four arguments
public void setItemNumber( int number )
{
itemNumber = number;
}
public int getItemNumber()
{
return itemNumber;
}
public void setItemName( String name )
{
itemName = name;
}
public String getitemName()
{
return itemName;
}
public void setItemTotal( int total )
{
itemTotal = ( total = 9 );
}
public int getItemTotal()
{
return itemTotal;
}
public void setItemPrice (double price)
{
itemPrice = ( price = 26738.0);
}
public double getItemPrice()
{
return itemPrice;
}
public double getValue()
{
return itemTotal * itemPrice;
}
}// end class Cars
Cars Inventory2 has 3 errors which I can not eliminate either.
Line 29 has an invalid method declaration; return type required.
gettotalInventory();
and a 'class" or 'interface' expected in line 45
public class CarsInventory2
{
public static void main( String args[ ] )
{
// create and initialize Cars array
Cars[ ] myCarArray = new Cars [7];
myCarArray[0] = new Cars( 2479, "Volkswagon CC", 20, 33000.00 );
myCarArray[1] = new Cars( 4862, "Ford Fusion", 10, 25000.00 );
myCarArray[2] = new Cars( 12945,"Subaru Legacy", 5, 21000.00 );
myCarArray[3] = new Cars( 46789, "Lincoln MKS", 4, 42000.00 );
myCarArray[4] = new Cars( 76042, "Chevy Cobalt", 7, 18000.00 );
myCarArray[5] = new Cars( 9210, "Honda Civic", 2, 23000.00 );
myCarArray[6] = new Cars( 4269, "Kia Optima", 12, 21000.00 );
}
public double gettotalInventory() ;
{
return totalInventory;
}
public double getProdInventory() ;
{
return ProdInventory;
}
// Output value for each array element
gettotalInventory();
{
for ( int i = 0; i < myCarArray.length; i++ )
{
System.out.println( "Product Number" + myCarArray[ i ]. getProdNumber() );
System.out.println( "Product Name" + myCarArray[ i ]. getProdName() );
System.out.println( "Total Units in Stock" + myCarArray[ i ]. getUnitsTotal() );
System.out.println( "Price Per Unit:" + myCarArray[ i ]. getUnitPrice() );
System.out.println( "Amount of Product Inventory:" + myCarArray[ i ]. getProdInv() );
System.out.println( "Total Inventory" + myCarArray[ i ]. getTotalInventory() );
}
} // end main
} // end CarsInventory2
The third bit of code is CarsInventory which is linked to my Cars code some how....aarrgghh!!! I am so lost it hurts my brain. I am gettin a compile error of ')' expected System.out.printf("%s %s\n", item getItemName() );
public class CarsInventory
{
public static void main( String args[])
{
// main method begins execution Car application
Cars item = new Cars(47036, " Toyota Civic", 9, 26738);
// get car details
System.out.println(" Car Inventory Program");
System.out.printf(" %s %d\n", " Item Number: ", item.getItemNumber() );
System.out.printf(" %s %s\n", " Item Name: ", item getItemName() );
System.out.printf(" %s %d\n", " Total items in stock: ", item.getItemTotal() );
System.out.printf(" %s $%g\n", " Price per item: ", item.getItemPrice() );
}// end main method
I have spent more than a dozen hours trying to eliminate errors.
Please help so I can get through this class with a decent grade.....
I am falling behind in my other class being obsessed with these problems.
Thanx for your assistance.
jim