title: Keep track of price and total cost
body: <p>I'm trying to keep track of each items cost, and add that to the total cost of all the items. When I run the program the last item cost and total cost is applied to each item. I feel like I should have another loop more dynamically placing the cost of each item and total cost.</p>
  
  <h1>Driver Class:</h1>
  
  <pre><code>    public class GroceryListTester
  {
     public static void main(String[] args)
     {
         GroceryList get = new GroceryList();
         get.start();
     }
  }
  </code></pre>
  
  <h1>CheckMail Class:</h1>
  
  <pre><code>import chn.util.*;
  import java.util.*;
  
  public class GroceryList
  {
          //Instance variables
          private int myNumItems;
          private double myItemCost;
          private double myTotalCost;
          Scanner keyboard = new Scanner(System.in);
  
          //Constructor
          public GroceryList()
          {
              myNumItems = 0;
              myTotalCost = 0;
          }
          //Methods
          public void start()
          {
              System.out.print('\u000C');
              getMyNumItems();
              getMyItemPrices();
              output();
          }
          public int getMyNumItems()
          {
              System.out.print("How many items would you like to purchase? =&gt; ");
              myNumItems = keyboard.nextInt();
  
              return myNumItems;
          }
          public double getMyItemPrices()
          {
              int n = 0; //Disp item number
  
              while(n  &lt; myNumItems)
              {
                  System.out.print("Please enter price of item #" +(n+1) +": ");
                  myItemCost = keyboard.nextDouble();
                  myTotalCost = myTotalCost + myItemCost;
                  ++n;
              }
  
              return myTotalCost;
          }
          public void output()
          {
              for(int n = 0; n &lt; myNumItems; ++n)
              {
                  System.out.println();
                  System.out.printf("%8s %8s %8s", "Item #" +(n + 1) , "Cost: $" +myItemCost, "Total: $" +myTotalCost);
  
              }
          }
  }
  </code></pre>
  
  <h1>Output:</h1>
  
  <pre><code>How many items would you like to purchase? =&gt; 3
  Please enter price of item #1: 1.25
  Please enter price of item #2: 1.75
  Please enter price of item #3: 1.50
  
   Item #1 Cost: $1.5 Total: $4.5
   Item #2 Cost: $1.5 Total: $4.5
   Item #3 Cost: $1.5 Total: $4.5
  </code></pre>