然后以同样手法处理frequentRenterPoints:
class Customer...
public String statement() {
int frequentRenterPoints = 0;
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
frequentRenterPoints += each.getFrequentRenterPoints();
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(each.getCharge()) + "\n";
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(getTotalCharge()) + " \n";
result += "You earned " + String.valueOf(frequentRenterPoints) +
"frequent renter points";
return result;
}
--------------------------------------------------------------------------------------------------------------------
public String statement() {
Enumeration rentals = _rentals.elements();
String result = "Rental Record for * " + getName() + "\n";
while(rentals.hasMoreElements()) {
Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录
result += "\t" + each.getMovie().getTitle() + "\t" +
String.valueOf(each.getCharge()) + "\n";
}
// add footer lines(结尾打印)
result += "Amount owed is " + String.valueOf(getTotalCharge()) + " \n";
result += "You earned " + String.valueOf(getTotalfrequentRenterPoints()) +
"frequent renter points";
return result;
}
// 译注:此即所谓query method
private int getTotalFrequentRenterPoints() {
int result = 0;
Enumeration rentals = _rentals.elements();
while(rentals.hasMoreElements()) {
Rental each = (Rental)rentals.nextElement();
result += each.getFrequentRenterPoints();
}
return result;
}