每次我运行我的 PairTester 类时,每个结果都会得到零。谁能告诉我为什么?
public class Pair {
private double val1;
private double val2;
public Pair(double aFirst, double aSecond) {
aFirst = val1;
aSecond = val2;
}
public double getSum() {
double sum = val1 + val2;
return sum;
}
public double getDifference() {
double difference = val1 - val2;
return difference;
}
public double getProduct() {
double product = val1 * val2;
return product;
}
public double getAverage() {
double average = (val1 + val2) / 2;
return average;
}
public double getAbsolute() {
double absolute = Math.abs(val1 - val2);
return absolute;
}
public double getMinimum() {
double minimum = Math.min(val1, val2);
return minimum;
}
public double getMaximum() {
double maximum = Math.max(val1, val2);
return maximum;
}
}
这是我的测试类:
public class PairTester {
public static void main(String[] args) {
Pair myPair = new Pair(11, 15);
System.out.println("Sum = " + myPair.getSum());
System.out.println("Difference = " + myPair.getDifference());
System.out.println("Average = " + myPair.getAverage());
System.out.println("Absolute = " + myPair.getAbsolute());
System.out.println("Minimum = " + myPair.getMinimum());
System.out.println("Maximum = " + myPair.getMaximum());
}
}