From f6c1cac663c621bc323640d81d8b037d22a85ebd Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 17:42:59 +0900 Subject: [PATCH] =?UTF-8?q?PriceType=E3=81=AB=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E7=A7=BB=E5=8B=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/video/domain/Movie.java | 21 +++-------------- src/main/java/video/domain/PriceType.java | 23 ++++++++++++++++++- src/main/java/video/domain/rental/Rental.java | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/main/java/video/domain/Movie.java b/src/main/java/video/domain/Movie.java index 51d07dc..6d2b23c 100644 --- a/src/main/java/video/domain/Movie.java +++ b/src/main/java/video/domain/Movie.java @@ -1,17 +1,10 @@ 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; @@ -30,16 +23,8 @@ 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("ビデオの区分が誤っています"); - } + public int movieAmount(int daysRented) { + return priceType.amount(daysRented); } + } \ No newline at end of file diff --git a/src/main/java/video/domain/PriceType.java b/src/main/java/video/domain/PriceType.java index ce30cba..6be1438 100644 --- a/src/main/java/video/domain/PriceType.java +++ b/src/main/java/video/domain/PriceType.java @@ -1,7 +1,28 @@ package video.domain; +import video.domain.price.ChildrenPrice; +import video.domain.price.NewReleasePrice; +import video.domain.price.RegularPrice; + public enum PriceType { CHILDREN, REGULAR, - NEW_RELEASE + NEW_RELEASE; + + private final RegularPrice regularPrice = new RegularPrice(); + private final NewReleasePrice newReleasePrice = new NewReleasePrice(); + private final ChildrenPrice childrenPrice = new ChildrenPrice(); + + 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("ビデオの区分が誤っています"); + } + } } diff --git a/src/main/java/video/domain/rental/Rental.java b/src/main/java/video/domain/rental/Rental.java index 2e514b2..b90ee02 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.amount(daysRented); + return movie.movieAmount(daysRented); } public int frequentRenterPoints() {