From ccd5123da92d4ecbed9ea0f3cebf3877882a9b30 Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 17:49:34 +0900 Subject: [PATCH 1/2] =?UTF-8?q?PriceType=E3=81=AE=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E3=81=ABPrice=E3=82=A4=E3=83=B3=E3=82=BF=E3=83=BC=E3=83=95?= =?UTF-8?q?=E3=82=A7=E3=83=BC=E3=82=B9=E3=82=92=E8=A8=AD=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/video/domain/PriceType.java | 26 +++++++++-------------- 1 file changed, 10 insertions(+), 16 deletions(-) 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); } } From 653c2e65addd6556600632e16e55d72da224654e Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 19:06:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E5=90=8D=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/video/domain/Movie.java | 2 +- src/main/java/video/domain/rental/Rental.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/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() {