如何访问 ID 的值以找到平均值?

How can I access value of ID to find the average?

我有静态方法 Das,它将采用 2 个 Car 类型的对象和 return id 的平均值。我很难访问 id 来找到平均值。任何帮助将不胜感激

这是我的代码

public class Car {

private int id;
private String name;

public Car(int id, String name)
{
this.id = id;
this.name = name;
}

public static int Das( Car C1 , Car C2) {
{
return (C1.id + C2.id)/2 ;
}

// getter and setter

Test.java

public class Test {

public static void main(String[] args) {

Car car1 = new Car(1,"A");
Car car2 = new Car(2,"V");
double A= Das(car1,car2);
System.out.println(A);
}}

对于 int return 会丢失分数的情况,请按以下步骤操作。

public static int findAveCustomerId(Customer C1 , Customer C2) {
   return (C1.id + C2.id)/2;
}

double return 不会丢失分数

public static double findAveCustomerId(Customer C1 , Customer C2) {
   return (C1.id + C2.id)/2.; // notice the decimal point.
}