diff --git a/src/main/java/video/domain/Movie.java b/src/main/java/video/domain/Movie.java index 6d2b23c..d73a614 100644 --- a/src/main/java/video/domain/Movie.java +++ b/src/main/java/video/domain/Movie.java @@ -23,7 +23,7 @@ public String getTitle() { return title; } - public int movieAmount(int daysRented) { + public int amount(int daysRented) { return priceType.amount(daysRented); } diff --git a/src/main/java/video/domain/PriceType.java b/src/main/java/video/domain/PriceType.java index 6be1438..5b15599 100644 --- a/src/main/java/video/domain/PriceType.java +++ b/src/main/java/video/domain/PriceType.java @@ -2,27 +2,21 @@ import video.domain.price.ChildrenPrice; import video.domain.price.NewReleasePrice; +import video.domain.price.Price; import video.domain.price.RegularPrice; public enum PriceType { - CHILDREN, - REGULAR, - NEW_RELEASE; + CHILDREN(new ChildrenPrice()), + REGULAR(new RegularPrice()), + NEW_RELEASE(new NewReleasePrice()); - private final RegularPrice regularPrice = new RegularPrice(); - private final NewReleasePrice newReleasePrice = new NewReleasePrice(); - private final ChildrenPrice childrenPrice = new ChildrenPrice(); + Price price; + + PriceType(Price price) { + this.price = price; + } int amount(int daysRented) { - switch (this) { - case REGULAR: - return regularPrice.amount(daysRented); - case NEW_RELEASE: - return newReleasePrice.amount(daysRented); - case CHILDREN: - return childrenPrice.amount(daysRented); - default: - throw new RuntimeException("ビデオの区分が誤っています"); - } + return price.amount(daysRented); } } diff --git a/src/main/java/video/domain/rental/Rental.java b/src/main/java/video/domain/rental/Rental.java index b90ee02..2e514b2 100644 --- a/src/main/java/video/domain/rental/Rental.java +++ b/src/main/java/video/domain/rental/Rental.java @@ -24,7 +24,7 @@ public Movie getMovie() { public int amount() { // 金額を計算 int daysRented = getDaysRented(); - return movie.movieAmount(daysRented); + return movie.amount(daysRented); } public int frequentRenterPoints() {