Exemple #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;
  }
Exemple #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;
  }
Exemple #3
0
 private int getTotalFrequentRenterPoints() {
   int result = 0;
   for (Rental rental : rentals) {
     result += rental.getFrequentRenterPoints();
   }
   return result;
 }
Exemple #4
0
 private double getTotalCharge() {
   double result = 0;
   for (Rental rental : rentals) {
     result += rental.getCharge();
   }
   return result;
 }
  @Override
  public Rental getSpecificRentalWithReviewsDAO(int rentalId) {
    Rental rental = getSpecificRentalDAO(rentalId);

    Hibernate.initialize(rental.getReviews());

    return rental;
  }
 public static Rental getLongerRental(Rental r1, Rental r2) {
   Rental longer = new Rental();
   int minutes1;
   int minutes2;
   minutes1 = r1.getHours() * Rental.MINUTES_IN_HOUR + r1.getExtraMinutes();
   minutes2 = r2.getHours() * Rental.MINUTES_IN_HOUR + r2.getExtraMinutes();
   if (minutes1 >= minutes2) longer = r1;
   else longer = r2;
   return longer;
 }
Exemple #7
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;
 }
 /** 打印金额、积分情况 */
 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);
 }
 public static void displayDetails(Rental r) {
   System.out.println("\nContract #" + r.getContractNumber());
   System.out.println(
       "For a rental of "
           + r.getHours()
           + " hours and "
           + r.getExtraMinutes()
           + " minutes, at a rate of "
           + r.HOUR_RATE
           + " the price is $"
           + r.getPrice());
 }
Exemple #10
0
  @Test
  public void testCreate() throws Exception {

    List<Fine> fine = new ArrayList<>();
    Fine newFine = new FineFactory().createFine(50, "Book not returned by duedate", false);
    fine.add(newFine);

    Rental rental = new RentalFactory().createRental(new Date(), new Date(), new Date(), fine);

    Assert.assertNotNull(rental);
    Assert.assertNotNull(rental.getTakeOutDate());
    Assert.assertNotNull(rental.getDueDate());
    Assert.assertNotNull(rental.getReturnDate());
    Assert.assertNotNull(fine);
  }
Exemple #11
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;
 }
Exemple #12
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;
 }
Exemple #13
0
  @Test
  public void testUpdate() throws Exception {

    List<Fine> fine = new ArrayList<>();
    Fine firstFine = new FineFactory().createFine(50, "Book not returned by duedate", false);
    fine.add(firstFine);

    Rental rental = new RentalFactory().createRental(new Date(), new Date(), new Date(), fine);

    Fine secondFine = new FineFactory().createFine(100, "Book not returned by duedate", false);
    fine.add(secondFine);

    Rental newRental = new Rental.Builder().copy(rental).fine(fine).build();

    Assert.assertEquals(50, rental.getFine().get(0).getFineAmout(), .2f);
    // Assert.assertEquals(100, newRental.getFine().get(0).getFineAmout(), .2f);

  }
Exemple #14
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;
 }
  public Rental removeRental(Rental rental) {
    getRentals().remove(rental);
    rental.setStaff(null);

    return rental;
  }
 public static void main(String[] args) {
   String contractNum;
   int minutes;
   contractNum = getContractNumber();
   minutes = getMinutes();
   Rental r1 = new Rental(contractNum, minutes);
   contractNum = getContractNumber();
   minutes = getMinutes();
   Rental r2 = new Rental(contractNum, minutes);
   contractNum = getContractNumber();
   minutes = getMinutes();
   Rental r3 = new Rental(contractNum, minutes);
   displayDetails(r1);
   displayDetails(r2);
   displayDetails(r3);
   System.out.println(
       "Of Contract #"
           + r1.getContractNumber()
           + " with a time of "
           + r1.getHours()
           + " hours and "
           + r1.getExtraMinutes()
           + " minutes,\n   and Contract #"
           + r2.getContractNumber()
           + " with a time of "
           + r2.getHours()
           + " hours and "
           + r2.getExtraMinutes()
           + " minutes,\n   the one with the longer time is Contract #"
           + getLongerRental(r1, r2).getContractNumber());
   System.out.println(
       "Of Contract #"
           + r1.getContractNumber()
           + " with a time of "
           + r1.getHours()
           + " hours and "
           + r1.getExtraMinutes()
           + " minutes,\n   and Contract #"
           + r3.getContractNumber()
           + " with a time of "
           + r3.getHours()
           + " hours and "
           + r3.getExtraMinutes()
           + " minutes,\n   the one with the longer time is Contract #"
           + getLongerRental(r1, r3).getContractNumber());
   System.out.println(
       "Of Contract #"
           + r2.getContractNumber()
           + " with a time of "
           + r2.getHours()
           + " hours and "
           + r2.getExtraMinutes()
           + " minutes,\n   and Contract #"
           + r3.getContractNumber()
           + " with a time of "
           + r3.getHours()
           + " hours and "
           + r3.getExtraMinutes()
           + " minutes,\n   the one with the longer time is Contract #"
           + getLongerRental(r2, r3).getContractNumber());
 }
Exemple #17
0
 public void addRentalLineItem(Rental rental) {
   statementBuilder.append(
       String.format("\t%s\t%.1f\n", rental.getTitle(), rental.determineRentalAmount()));
 }
Exemple #18
0
 /** Sets the Rental object */
 public void setRental(Rental rental) {
   this.rentalId = rental.getId();
   setDirty();
 }
  public Rental addRental(Rental rental) {
    getRentals().add(rental);
    rental.setStaff(this);

    return rental;
  }