I am trying to change this from an array to an arraylist but am having trouble.
First, I need to create the arraylist and get the input to create the shoppingitems, which include a bunch of different input (priority, cost, name, quantity).
For the array, I had this:
Expand|Select|Wrap|Line Numbers
- public static void main(String[] args)
- {
- ShoppingList go = new ShoppingList();
- go.getElement();
- go.Sort();
- System.out.println("hello");
- go.displayResults();
- }
Expand|Select|Wrap|Line Numbers
- public void getElement(){
- System.out.println("You can add seven items to purchase when prompted ");
- shoppingList = new ShoppingItem[numItems]; //creation of new array object
- for (int i = 0; i<= numItems - 1; i++)
- {
- shoppingList[i] = new ShoppingItem(); //shopping item objects created
- System.out.println("Enter data for the shopping item " + i);
- shoppingList[i].readInput();
- System.out.println();
- }
- }
So with my arraylist, I'm thinking it should be something like this?
Expand|Select|Wrap|Line Numbers
- public static void main(String[] args)
- {
- ArrayList<ShoppingItem>ShoppingList = new ArrayList<ShoppingItem>();
- ShoppingList.add(getElement());