Assuming your Car
class has a getter method for price, you can simply use
System.out.println (car.get(i).getPrice());
where i
is the index of the element.
You can also use
Car c = car.get(i);
System.out.println (c.getPrice());
You also need to return totalprice
from your function if you need to store it
main
public static void processCar(ArrayList<Car> cars){
int totalAmount=0;
for (int i=0; i<cars.size(); i++){
int totalprice= cars.get(i).computeCars ();
totalAmount=+ totalprice;
}
}
And change the return
type of your function
public int computeCars (){
int totalprice= price+tax;
System.out.println (name + "\t" +totalprice+"\t"+year );
return totalprice;
}