Ok so i am trying to redo my inventory program but the problem is that it won't run because i don't have a main method. Every time i try to put a main method in I get an error. Is there something wrong with my code thats keeping me from putting in a working main method??? Please help.
package inventory;
// Import the format class to format values into currency format.
import java.text.DecimalFormat;
public class Inventory {
int inventorySize = 5;
private Car items[] = new Car[inventorySize];
// format values into currency form.
DecimalFormat formatter = new DecimalFormat("$##,###.00");
public void addCar(Car item) {
for (int i = 0; i < inventorySize; i++) {
if (items[i] == null) {
items[i] = item;
return;
}
}
}
public double getTotalInvValue() {
double sumOfInventory = 0.0;
for (Car item : items) {
if (item != null) {
sumOfInventory += item.getItemValue();
}
}
return sumOfInventory;
}
// Prints the inventory list including name, quantity, price, and total stock value for each item.
public void printInventory() {
System.out.println("Printing items in inventory...\n");
boolean hasItems = false;
for (Car item : items) {
if (item != null) {
hasItems = true;
System.out.println(item.toString() + " stock: " + item.getInstock() + " Value of Stock: " + formatter.format(item.getItemValue()));
}
}
// for no items
if (!hasItems) { System.out.println("Inventory is empty .\n"); }
}
}
package inventory;
public class Car {
// Private variables
private String name;
private int stock;
private double price;
private int productid = 0;
// Constructor that user can specify a name, quantity, and price for items.
public Car (int productId, String itemname, int instock, double itemprice) {
productid = productId;
setName(itemname);
setinstock(instock);
setPrice(itemprice);
}
public void setName(String itemname) {
name = itemname;
}
// Sets whats in stock if negative, defaults to zero.
public void setinstock(int Instock) {
int instock = 0;
if ( Instock > 0) {
Instock = stock;
}
else { stock = 0; }
}
// Set price of a product and defaults it to zero if negative.
public void setPrice(double itemPrice) {
if (itemPrice > 0.00) {
price = itemPrice;
}
else { price = 0.00; }
}
// Get the product's name
public String getName() {
return name;
}
public int getInstock() {
int Instock = 0;
return stock;
}
public double getPrice() {
return price;
}
// Calculate the value of stock on this particular item.
public double getItemValue() {
return (price * (double)stock);
}
// String representation of the product
@Override
public String toString() {
return name + " - " + price;
}
}