title: method to add objects to ArrayList using user input
body: <p>Can't take my head around the following: There are  2 classes - "Item", where attributes (Name, Price) and constructors are set, and main "Store". In the last one - Arraylist, which fills up with Items depending on user input.  The code works. </p>
  
  <p>Here is the question: Is there any way to put all from the main class, apart from "ArrayList listOfItems=new ArrayList();" line  into a method "addItem()" and then just call the method?  I do not know how to do it. Tried a lot.  </p>
  
  <p>Thank you</p>
  
  <pre><code>package store;
  
  import java.util.ArrayList;
  import java.util.Scanner;
  
  public class Store extends Item {
  
  public static void main(String[] args) {        
  
     ArrayList&lt;Item&gt; listOfItems=new ArrayList&lt;Item&gt;();
  
      for(int i=0;i&lt;2;i++){
  
          System.out.println("ENTER NAME");
          Scanner addName=new Scanner (System.in);
          String name=(addName.nextLine());
  
          System.out.println("ENTER PRICE");
          Scanner addPrice=new Scanner (System.in);
          double price=(addPrice.nextDouble());
  
          listOfItems.add(new Item(name,price));
      }
      for(Item list:listOfItems){
          System.out.println("NAME "+list.getName()+", PRICE "+list.getPrice());
      }
    }
  }
  </code></pre>