From 996f0f55397fc9735b3416920ef074ac95433c33 Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 17:28:11 +0900 Subject: [PATCH 1/2] =?UTF-8?q?amount=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89?= =?UTF-8?q?=E3=82=92movie=E3=82=AF=E3=83=A9=E3=82=B9=E3=81=AB=E7=A7=BB?= =?UTF-8?q?=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/rental/Rental.java | 22 ++----------------- 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/main/java/video/domain/Movie.java b/src/main/java/video/domain/Movie.java index 82a0978..daf8262 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 (getPriceType()) { + 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() { From 479d7a9a831b0f56211e3858410082f7d723ba7a Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 17:32:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?getPrice()=E3=83=A1=E3=82=BD=E3=83=83?= =?UTF-8?q?=E3=83=89=E3=82=92=E4=BD=BF=E3=82=8F=E3=81=9A=E3=80=81=E3=83=95?= =?UTF-8?q?=E3=82=A3=E3=83=BC=E3=83=AB=E3=83=89=E3=81=AEpriceType=E3=82=92?= =?UTF-8?q?=E4=BD=BF=E3=81=86=E3=82=88=E3=81=86=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 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/video/domain/Movie.java b/src/main/java/video/domain/Movie.java index daf8262..51d07dc 100644 --- a/src/main/java/video/domain/Movie.java +++ b/src/main/java/video/domain/Movie.java @@ -31,7 +31,7 @@ public String getTitle() { } public int amount(int daysRented) { - switch (getPriceType()) { + switch (priceType) { case REGULAR: return regularPrice.amount(daysRented); case NEW_RELEASE: