Reputation: 242
I'm a beginner programmer and am tasked to write an inventory program. I have only programmed using BlueJay so far, but am about to learn how to use the vim editor. When programming with BlueJay, you didn't need to write a main method. I'm so lost about how to write the main method and everything I researched over the internet didn't seem to explain or help much.
I have already started the design of the program where I have an Inventory class and an Item class. How would I go about starting this project? Like what do I need to do with the main method and how would that work?
Thanks
Here is the code I have so far.
import java.util.*;
public class Inventory
{
private ArrayList<Item>inventory;
/**
* Constructor for objects of class Inventory
*/
public Inventory()
{
inventory = new ArrayList<Item>();
}
/**
* Adds an Item to the Inventory.
*/
public void addItem(String name, int amount, double price, int location)
{
boolean done = false;
if(inventory.size() == 0)
{
inventory.add(new Item(name, amount, price, location));
}
else
{
for(int i = 0; (!done)&&(i < inventory.size()); i++)
{
if(inventory.get(i).getName().equals(name))
{
System.out.println("Item name in use. Please use another name.");
done = true;
}
else
{
inventory.add(new Item(name, amount, price, location));
done = true;
}
}
}
}
/**
* Deletes an Item from the Inventory.
*/
public void deleteItem(String name)
{
...........
}
/**
* Search for an Item.
*/
public void searchItem(String name)
{
...........
}
}
Upvotes: 0
Views: 1792
Reputation: 13535
There are answers for this everywhere in Java documentation. But here it is.
public class App {
public static void main(String [] args)
{
//start here
}
}
Upvotes: 4