From ae43d2bda2c9472433d07776f6163a620259344d Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 16:46:47 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E6=96=99=E9=87=91=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E3=83=A1=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E5=8C=BA=E5=88=86?= =?UTF-8?q?=E3=81=94=E3=81=A8=E3=81=AB=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/video/domain/rental/Rental.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/video/domain/rental/Rental.java b/src/main/java/video/domain/rental/Rental.java index 8e5dbb7..b210acc 100644 --- a/src/main/java/video/domain/rental/Rental.java +++ b/src/main/java/video/domain/rental/Rental.java @@ -22,20 +22,33 @@ public Movie getMovie() { public int amount() { // 金額を計算 + int daysRented = getDaysRented(); switch (getMovie().getPriceType()) { case REGULAR: - if (getDaysRented() <= 2) return 200; - return 200 + (getDaysRented() - 2) * 150; + return regularPrice(daysRented); case NEW_RELEASE: - return getDaysRented() * 300; + return newReleasePrice(daysRented); case CHILDREN: - if (getDaysRented() <= 3) return 150; - return 150 + (getDaysRented() - 3) * 150; + return childrenPrice(daysRented); default: throw new RuntimeException("ビデオの区分が誤っています"); } } + private int regularPrice(int daysRented) { + if (daysRented <= 2) return 200; + return 200 + (daysRented - 2) * 150; + } + + private int newReleasePrice(int daysRented) { + return daysRented * 300; + } + + private int childrenPrice(int daysRented) { + if (daysRented <= 3) return 150; + return 150 + (daysRented - 3) * 150; + } + public int frequentRenterPoints() { // 新作を二日以上借りた場合はボーナスポイント if ((getMovie().getPriceType() == PriceType.NEW_RELEASE) && From 9926499b7daf35047059103b867e1f1535cac8dc Mon Sep 17 00:00:00 2001 From: stgctkm Date: Tue, 22 Aug 2023 16:54:01 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E5=8C=BA=E5=88=86=E3=81=94=E3=81=A8?= =?UTF-8?q?=E3=81=AE=E6=96=99=E9=87=91=E8=A8=88=E7=AE=97=E3=83=A1=E3=82=BD?= =?UTF-8?q?=E3=83=83=E3=83=89=E3=82=92=E5=A7=94=E8=AD=B2=E3=81=99=E3=82=8B?= =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../video/domain/rental/ChildrenPrice.java | 11 +++++++++ .../video/domain/rental/NewReleasePrice.java | 10 ++++++++ .../video/domain/rental/RegularPrice.java | 11 +++++++++ src/main/java/video/domain/rental/Rental.java | 23 +++++-------------- 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 src/main/java/video/domain/rental/ChildrenPrice.java create mode 100644 src/main/java/video/domain/rental/NewReleasePrice.java create mode 100644 src/main/java/video/domain/rental/RegularPrice.java diff --git a/src/main/java/video/domain/rental/ChildrenPrice.java b/src/main/java/video/domain/rental/ChildrenPrice.java new file mode 100644 index 0000000..8c8c32a --- /dev/null +++ b/src/main/java/video/domain/rental/ChildrenPrice.java @@ -0,0 +1,11 @@ +package video.domain.rental; + +public class ChildrenPrice { + public ChildrenPrice() { + } + + int price(int daysRented) { + if (daysRented <= 3) return 150; + return 150 + (daysRented - 3) * 150; + } +} \ No newline at end of file diff --git a/src/main/java/video/domain/rental/NewReleasePrice.java b/src/main/java/video/domain/rental/NewReleasePrice.java new file mode 100644 index 0000000..0bc61e3 --- /dev/null +++ b/src/main/java/video/domain/rental/NewReleasePrice.java @@ -0,0 +1,10 @@ +package video.domain.rental; + +public class NewReleasePrice { + public NewReleasePrice() { + } + + int price(int daysRented) { + return daysRented * 300; + } +} \ No newline at end of file diff --git a/src/main/java/video/domain/rental/RegularPrice.java b/src/main/java/video/domain/rental/RegularPrice.java new file mode 100644 index 0000000..dcb05d0 --- /dev/null +++ b/src/main/java/video/domain/rental/RegularPrice.java @@ -0,0 +1,11 @@ +package video.domain.rental; + +public class RegularPrice { + public RegularPrice() { + } + + int price(int daysRented) { + if (daysRented <= 2) return 200; + return 200 + (daysRented - 2) * 150; + } +} \ 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 b210acc..55bf1c6 100644 --- a/src/main/java/video/domain/rental/Rental.java +++ b/src/main/java/video/domain/rental/Rental.java @@ -4,6 +4,9 @@ import video.domain.PriceType; 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; @@ -25,30 +28,16 @@ public int amount() { int daysRented = getDaysRented(); switch (getMovie().getPriceType()) { case REGULAR: - return regularPrice(daysRented); + return regularPrice.price(daysRented); case NEW_RELEASE: - return newReleasePrice(daysRented); + return newReleasePrice.price(daysRented); case CHILDREN: - return childrenPrice(daysRented); + return childrenPrice.price(daysRented); default: throw new RuntimeException("ビデオの区分が誤っています"); } } - private int regularPrice(int daysRented) { - if (daysRented <= 2) return 200; - return 200 + (daysRented - 2) * 150; - } - - private int newReleasePrice(int daysRented) { - return daysRented * 300; - } - - private int childrenPrice(int daysRented) { - if (daysRented <= 3) return 150; - return 150 + (daysRented - 3) * 150; - } - public int frequentRenterPoints() { // 新作を二日以上借りた場合はボーナスポイント if ((getMovie().getPriceType() == PriceType.NEW_RELEASE) &&