![]() |
| private double amountFor(Rental aRental) { return aRental.getCharge(); } |
| /** * @param this * @return */ private double getCharge() { …… } |
![]() |
![]() |
| public String statement() { …… double thisAmount = each.getCharge(); …… } |
![]() |
| public String statement() { double totalAmount = 0; // 总消费金额 int frequentRenterPoints = 0; // 常客积点 Enumeration rentals = _rentals.elements(); String result = "Rental Record for " + getName() + "\n"; while(rentals.hasMoreElements()){ Rental each = (Rental)rentals.nextElement(); //取得一笔租借记录 // add frequent renter points(累加 常客积点) frequentRenterPoints ++; // add bouns 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(each.getCharge()) + "\n"; totalAmount += each.getCharge(); } // add footer lines(结尾打印) result += "Amount owed is " + String.valueOf(totalAmount) + "\n"; result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points"; return result; } |