0

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)
    {
        ...........
    }
}
DaveMcFave
  • 232
  • 1
  • 4
  • 13

1 Answers1

4

There are answers for this everywhere in Java documentation. But here it is.

public class App {

    public static void main(String [] args)
    {
        //start here
    }
}
DevZer0
  • 13,433
  • 7
  • 27
  • 51
  • I understand that part, but what should go where the "start here" is? I asked the question more so for the design purpose. What is actual supposed to be in the main method? – DaveMcFave Sep 05 '14 at 02:58
  • @DaveMcFave - what you want your program to actually do goes into the main method. You said you have an Inventory class and an Item class. I don't know what either of them do, but perhaps instantiating them would be a good start. `Inventory myInventory = new Inventory();`. – Deco Sep 05 '14 at 03:06
  • So, would I just write all the methods I want the client to be able to use in the main method? For example, the constructor and the mutating methods? – DaveMcFave Sep 05 '14 at 03:07
  • 1
    @DaveMcFave - Check out the Getting Started tutorial that was linked in your question as it goes through step-by-step what Hello World does and how it works. I also suggest going back to your instructor and getting them to explain the fundamentals of how a program works in Java (and in general). – Deco Sep 05 '14 at 03:12