| Перенос расчёта задолженности | Страница 20 |
Иногда я оставляю старый метод. Это бывает полезно, если это public метод, и мне не хочется менять интерфейс в других классах.
Конечно, осталось ещё кое что, что мне хотелось бы сделать в Rental.getCharge, но пока оставим его и вернемся к Customer.statement.
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentals = this.rentals.elements();
String result = "Rental Record for "+getName()+"\n";
while( rentals.hasMoreElements()) {
double thisAmount = 0;
Rental each = ( Rental) rentals.nextElement();
thisAmount = each.getCharge();
// add frequent renter points
frequentRenterPoints++;
// add bonus for a two day new release rental
if( each.getMovie().getPriceCode()==Movie.NEW_RELEASE &&
each.getDaysRented()>1) frequentRenterPoints++;
// show figures for this rental
result += "\t"+each.getMovie().getTitle()+"\t"+
String.valueOf( thisAmount)+"\n";
totalAmount += thisAmount;
}
// add footer lines
result += "Amount owned is "+String.valueOf( totalAmount)+"\n";
result += "You earned "+String.valueOf( frequentRenterPoints)+
" frequent renter points";
return result;
}
Оглавление | << страница 19 | страница 21 >>