我感谢任何人在这里的帮助。下面是我的类,其中包含我所有的 setter 和 getter,在我的主类中,我创建了 3 个客户,在值参数中,我有 3 个不同的数字。我需要做的是找到所有这些值的总价值,有什么方法可以创建一个方法(参见下面的 bookingValue)来计算并添加每个客户价值参数的总和?请记住,3 不是一个固定数字,因此如果我选择添加更多客户,该方法不应受到影响。这可能真的很基本,但如果有人能让我走上正确的道路,那就太好了,干杯
public class Customer
{
private int identity;
private String name;
private String address;
private double value;
public Customer()
{
identity = 0;
name = "";
address = "";
value = 0.0;
}
public void setIdentity(int identityParam)
{
identity = identityParam;
}
public int getIdentity()
{
return identity;
}
public void setName(String nameParam)
{
name = nameParam;
}
public String getName()
{
return name;
}
public void setAddress(String addressParam)
{
address = addressParam;
}
public String getAddress()
{
return address;
}
public void setValue(double valueParam)
{
value = valueParam;
}
public double getCarCost()
{
return value;
}
public void printCustomerDetails()
{
System.out.println("The identity of the customer is: " + identity);
System.out.println("The name of the customer is: " + name);
System.out.println("The address of the customer is: " + address);
System.out.println("The value of the customers car is: " + value + "\n");
}
public void bookingValue()
{
//Ive tried messing around with a for loop here but i cant seem to get it working
}
}