Skip to content
Draft
Show file tree
Hide file tree
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
22 changes: 1 addition & 21 deletions src/main/java/video/domain/Customer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public RentalResult rentalMovies() {
int totalAmount = 0;
int frequentRenterPoints = 0;
for (Rental each : rentals) {
int thisAmount = amount(each);
int thisAmount = each.amount();
// レンタルポイントを加算
frequentRenterPoints++;
// 新作を二日以上借りた場合はボーナスポイント
Expand All @@ -39,24 +39,4 @@ 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;
}
}
21 changes: 21 additions & 0 deletions src/main/java/video/domain/Rental.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,25 @@ public int getDaysRented() {
public Movie getMovie() {
return movie;
}

int amount() {
int thisAmount = 0;
// 金額を計算
switch (getMovie().getPriceType()) {
case REGULAR:
thisAmount += 200;
if (getDaysRented() > 2)
thisAmount += (getDaysRented() - 2) * 150;
break;
case NEW_RELEASE:
thisAmount += getDaysRented() * 300;
break;
case CHILDREN:
thisAmount += 150;
if (getDaysRented() > 3)
thisAmount += (getDaysRented() - 3) * 150;
break;
}
return thisAmount;
}
}
57 changes: 57 additions & 0 deletions src/test/java/video/domain/RentalTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package video.domain;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

class RentalTest {

Movie 子供用作品_となりのトトロ = new Movie("となりのトトロ", PriceType.CHILDREN);
Movie 旧作_トップガン = new Movie("トップガン", PriceType.REGULAR);
Movie 新作_君たちはどう生きるか = new Movie("君たちはどう生きるか", PriceType.NEW_RELEASE);
@Test
void 新作を4日のレンタル料金() {
Rental sut = new Rental(新作_君たちはどう生きるか, 4);

double result = sut.amount();

assertEquals(1200, result);
}


@Test
void 旧作を2日のレンタル料金() {
Rental sut = new Rental(旧作_トップガン, 2);

double result = sut.amount();

assertEquals(200, result);
}

@Test
void 旧作を3日のレンタル料金() {
Rental sut = new Rental(旧作_トップガン, 3);

double result = sut.amount();

assertEquals(350, result);
}

@Test
void 子供用作品を4日のレンタル料金() {
Rental sut = new Rental(子供用作品_となりのトトロ, 4);

double result = sut.amount();

assertEquals(300, result);
}

@Test
void 子供用作品を3日のレンタル料金() {
Rental sut = new Rental(子供用作品_となりのトトロ, 3);

double result = sut.amount();

assertEquals(150, result);
}
}