Exemplo n.º 1
0
  public String statement() {
    double totalAmount = 0;
    int frequentRenterPoints = 0;
    Enumeration rentals = _rentals.elements();
    String result = "Rental Record for " + getName() + "\n";

    while (rentals.hasMoreElements()) {
      double thisAmount = 0;
      Rental each = (Rental) rentals.nextElement();
      switch (((Movie) (each.getMovie())).getPriceCode()) {
        case Movie.REGULAR:
          thisAmount += 2;
          if (each.getDaysRented() > 2) thisAmount += (each.getDaysRented() - 2) * 1.5;
          break;
        case Movie.NEW_RELEASE:
          thisAmount += each.getDaysRented() * 3;
          break;
        case Movie.CHILDREN:
          thisAmount += 1.5;
          if (each.getDaysRented() > 3) thisAmount += (each.getDaysRented() - 3) * 1.5;
          break;
      }

      frequentRenterPoints++;
      if ((((Movie) (each.getMovie())).getPriceCode() == Movie.NEW_RELEASE)
          && each.getDaysRented() > 1) frequentRenterPoints++;
      result +=
          "\t" + ((Movie) (each.getMovie())).getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
      totalAmount += thisAmount;
    }

    result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
    result += "You earned " + String.valueOf(frequentRenterPoints) + "frquent renter points";
    return result;
  }
Exemplo n.º 2
0
  public String statment() {
    double totalAmount = 0;
    int frequentRentalPoints = 0;
    Enumeration retals = _rentals.elements();
    String result = "Rental Record for " + getName() + "\n";
    while (retals.hasMoreElements()) {
      double thisAmount = 0;
      Rental each = (Rental) retals.nextElement();
      // ***리팩토링*** : 메소드 추출
      thisAmount = amountFor(each);
      // 포인트 추가
      frequentRentalPoints++;
      // 최신을 이틀 이상 대여하는 경우 추가 포인트 제공
      if ((each.getMovie().getPriceCode() == Movie.NEW_RELEASE) && each.getDaysRented() >= 2) {
        frequentRentalPoints++;
      }
      // 이 대여에 대한 요금 계산결과 표시
      result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(thisAmount) + "\n";
      totalAmount += thisAmount;
    } // end while

    // 풋터 추가
    // result +="Amount owed is "+String.valueOf(totalAmount)+"\n";
    // result +="You earned"+String.valueOf(frequentRentalPoints)+"frequent rental points";
    result = String.valueOf(totalAmount);
    return result;
  }
Exemplo n.º 3
0
 /** 打印金额、积分情况 */
 public void printMssage() {
   double totalPrice = 0;
   int fre = 0;
   Iterator iterator = list.iterator(); // 获取迭代器
   while (!iterator.isDone()) {
     Rental r = (Rental) iterator.getCurrent();
     totalPrice += r.getMovie().getPrice(r.getDays());
     fre += r.getMovie().getFre(r.getDays());
     iterator.next();
   }
   System.out.println(this.name + "您消费的金额是:" + totalPrice + "您这次所获得的积分是:" + fre);
 }
Exemplo n.º 4
0
 private double amountFor(Rental each) {
   double thisAmount = 0;
   // 각 영화에 대한 요금 결정
   System.out.println("movie :" + each.getMovie());
   switch (each.getMovie().getPriceCode()) {
     case Movie.REGULAR:
       thisAmount += 2;
       if (each.getDaysRented() > 2) thisAmount += (each.getDaysRented() - 2) * 1.5;
       break;
     case Movie.NEW_RELEASE:
       thisAmount += (each.getDaysRented()) * 3;
       break;
     case Movie.CHILDREN:
       thisAmount += 2;
       if (each.getDaysRented() > 3) thisAmount += (each.getDaysRented() - 3) * 1.5;
       break;
   }
   return thisAmount;
 }
Exemplo n.º 5
0
 public String statement() {
   String result = "Rental Record for " + getName() + "\n";
   for (Rental rental : rentals) {
     result +=
         "\t" + rental.getMovie().getTitle() + "\t" + String.valueOf(rental.getCharge()) + "\n";
   }
   result += "Amount owed is " + String.valueOf(getTotalCharge()) + "\n";
   result +=
       "You earned " + String.valueOf(getTotalFrequentRenterPoints()) + " frequent renter points";
   return result;
 }
Exemplo n.º 6
0
 /**
  * _rentals.elements().nextElement() getCharge() getFrequentRenterPoints() getMovie() getTitle()
  */
 public String statement() { // O(n)
   double totalAmount = 0;
   int frequentRenterPoints = 0;
   String result = "Rental Record for " + getName() + "\n";
   Enumeration<Rental> rentals = _rentals.elements();
   while (rentals.hasMoreElements()) {
     Rental each = rentals.nextElement();
     totalAmount += each.getCharge();
     frequentRenterPoints += each.getFrequentRenterPoints();
     result += "\t" + each.getMovie().getTitle() + "\t" + String.valueOf(each.getCharge()) + "\n";
   }
   result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
   result += "You earned " + String.valueOf(frequentRenterPoints) + " frequent renter points";
   return result;
 }
Exemplo n.º 7
0
 public String htmlStatement() {
   String result = "<H1>Rental Record for <EM>" + getName() + "</EM></H1><P>\n";
   for (Rental rental : rentals) {
     result +=
         "\t"
             + rental.getMovie().getTitle()
             + "\t"
             + String.valueOf(rental.getCharge())
             + "<BR>\n";
   }
   result += "<P>You owe <EM>" + String.valueOf(getTotalCharge()) + "</EM><P>\n";
   result +=
       "You earned <EM>"
           + String.valueOf(getTotalFrequentRenterPoints())
           + "</EM> frequent renter points";
   return result;
 }