ivaneeo's blog

自由的力量,自由的生活。

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
然后以同样手法处理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;
}
posted on 2005-08-15 14:10 ivaneeo 阅读(129) 评论(0)  编辑  收藏 所属分类: refactoring-从地狱中重生

只有注册用户登录后才能发表评论。


网站导航: