I'm trying to add together a specific attribute of my objects(that are stored in an arraylist) using a for loop. I've tested it, and for some reason only one object gets repeatedly called. The method I am referring to is getCostOfRun(). There is more code, if you require more context please just ask.
import java.util.ArrayList;
import java.util.Arrays;
public class Phone
{
private static String Brand;
private static String Type;
private static String Model;
private static String UniqueID;
private static int ManufCost;
public static ArrayList<Phone> Phones = new ArrayList<Phone>();
public static int counter;
public Phone(String Brand, String Type, String Model, String UniqueID, int ManufCost)
{
this.Brand=Brand;
this.Type=Type;
this.Model=Model;
this.UniqueID=UniqueID;
this.ManufCost=ManufCost;
Phones.add(this);
counter =counter +1;
System.out.println(counter);
}
public static int getCostOfRun()
{
int TotalCost=0;
int tempcost=0;
int count=0;
while (Phones.size() > count) {
tempcost=Phones.get(count).ManufCost;
System.out.println(tempcost);
TotalCost=TotalCost+tempcost;
System.out.println(TotalCost);
count++;
}
return TotalCost;
}