How do I get the total price from my carList?
<p>I am creating a class called <code>Car</code> with a method called <code>TotalPrice</code> which will take an array of <code>Car</code>s and calculate the total for the list. I have implemented a client method <code>totalPrice</code>, which accepts a list (<code>ArrayUnsortedList carList</code>) of cars and returns an integer equal to the total cost of the cars on the list.</p>

<p>I am stuck on writing the test driver so that I can test my actual <code>Car</code> class program.</p>

<p>Here's my code for the <code>Car</code> class:</p>

<pre><code>public class Car
{
   int year;
   String make;
   String model;
   int price;

   public Car(int year, String make, String model, int price) {
      this.year = year;
      this.make = make;
      this.model = model;
      this.price = price;      
   }

   public int getYear() {
      return this.year;
   }

   public String getMake() {
      return make;
   }

   public String getModel() {
      return model;
   }

   public int getPrice() {
      return this.price;
   }

   public static int totalPrice(ArrayUnsortedList carList) {
      int totalPrice = 0;
      for(int i=carList.size(); i&gt;0; i--)
      {

         totalPrice += ((Car)carList.getNext()).getPrice();
      }
      return totalPrice;
   }      
} 
</code></pre>

<p>Here's my test drive class:</p>

<pre><code>import java.util.Scanner;
import java.util.ArrayList;

public class CarList{

   public static void main (String [] args) {

      ArrayUnsortedList&lt;Car&gt; carList = new ArrayUnsortedList&lt;Car&gt;();  
      Car car1, car2;

      car1 = new Car(2016, "BMW", "M4", 65700);
      carList.add(car1);    
      car1 = new Car(2016, "Mercedes-Benz", "C300", 38950);
      carList.add(car1);    
      car2 = new Car(2016, "Lexus", "GS F", 84440);
      carList.add(car2);

      System.out.println(Car.totalPrice(carList));

   }   

}
</code></pre>

<p>UPDATE********</p>

<p><em>I have to use ArrayUnsortedList that is given.</em></p>

<p>Here are the rest of the codes: <a href="https://gist.github.com/76342ck/31cf07f5742b890af0b5" rel="nofollow">GITHUB</a></p>

<p><strong>UPDATE</strong>
<em>Now I am getting the wrong totalPrice?</em></p>

<p>65700 + 38950 + 84440 = 189090</p>

<p>But I get 253320???</p>

<pre><code> ----jGRASP exec: java CarList

253320

 ----jGRASP: operation complete.
</code></pre>