diff --git a/src/main/java/video/domain/Movie.java b/src/main/java/video/domain/Movie.java index 82a0978..51d07dc 100644 --- a/src/main/java/video/domain/Movie.java +++ b/src/main/java/video/domain/Movie.java @@ -1,10 +1,18 @@ package video.domain; +import video.domain.price.ChildrenPrice; +import video.domain.price.NewReleasePrice; +import video.domain.price.RegularPrice; + public class Movie { private String title; PriceType priceType; + private final RegularPrice regularPrice = new RegularPrice(); + private final NewReleasePrice newReleasePrice = new NewReleasePrice(); + private final ChildrenPrice childrenPrice = new ChildrenPrice(); + public Movie(String title, PriceType priceType) { this.title = title; this.priceType = priceType; @@ -21,4 +29,17 @@ public void setPriceType(PriceType priceType) { public String getTitle() { return title; } + + public int amount(int daysRented) { + switch (priceType) { + case REGULAR: + return regularPrice.amount(daysRented); + case NEW_RELEASE: + return newReleasePrice.amount(daysRented); + case CHILDREN: + return childrenPrice.amount(daysRented); + default: + throw new RuntimeException("ビデオの区分が誤っています"); + } + } } \ No newline at end of file diff --git a/src/main/java/video/domain/rental/Rental.java b/src/main/java/video/domain/rental/Rental.java index 63013ee..2e514b2 100644 --- a/src/main/java/video/domain/rental/Rental.java +++ b/src/main/java/video/domain/rental/Rental.java @@ -2,14 +2,9 @@ import video.domain.Movie; import video.domain.PriceType; -import video.domain.price.ChildrenPrice; -import video.domain.price.NewReleasePrice; -import video.domain.price.RegularPrice; public class Rental { - private final RegularPrice regularPrice = new RegularPrice(); - private final NewReleasePrice newReleasePrice = new NewReleasePrice(); - private final ChildrenPrice childrenPrice = new ChildrenPrice(); + private Movie movie; private int daysRented; @@ -29,20 +24,7 @@ public Movie getMovie() { public int amount() { // 金額を計算 int daysRented = getDaysRented(); - return amount(daysRented); - } - - private int amount(int daysRented) { - switch (movie.getPriceType()) { - case REGULAR: - return regularPrice.amount(daysRented); - case NEW_RELEASE: - return newReleasePrice.amount(daysRented); - case CHILDREN: - return childrenPrice.amount(daysRented); - default: - throw new RuntimeException("ビデオの区分が誤っています"); - } + return movie.amount(daysRented); } public int frequentRenterPoints() {