Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/main/java/video/domain/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,7 @@ public RentalResult rentalMovies() {
int totalAmount = 0;
int frequentRenterPoints = 0;
for (Rental each : rentals) {
int thisAmount = 0;
// 一行ごとに金額を計算
switch (each.getMovie().getPriceType()) {
case REGULAR:
thisAmount += 200;
if (each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 150;
break;
case NEW_RELEASE:
thisAmount += each.getDaysRented() * 300;
break;
case CHILDREN:
thisAmount += 150;
if (each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 150;
break;
}
int thisAmount = amount(each);
// レンタルポイントを加算
frequentRenterPoints++;
// 新作を二日以上借りた場合はボーナスポイント
Expand All @@ -54,4 +38,25 @@ public RentalResult rentalMovies() {

return new RentalResult(totalAmount, frequentRenterPoints);
}

private int amount(Rental each) {
int thisAmount = 0;
// 金額を計算
switch (each.getMovie().getPriceType()) {
case REGULAR:
thisAmount += 200;
if (each.getDaysRented() > 2)
thisAmount += (each.getDaysRented() - 2) * 150;
break;
case NEW_RELEASE:
thisAmount += each.getDaysRented() * 300;
break;
case CHILDREN:
thisAmount += 150;
if (each.getDaysRented() > 3)
thisAmount += (each.getDaysRented() - 3) * 150;
break;
}
return thisAmount;
}
}