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 8e5dbb7..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; @@ -22,15 +25,14 @@ 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.price(daysRented); case NEW_RELEASE: - return getDaysRented() * 300; + return newReleasePrice.price(daysRented); case CHILDREN: - if (getDaysRented() <= 3) return 150; - return 150 + (getDaysRented() - 3) * 150; + return childrenPrice.price(daysRented); default: throw new RuntimeException("ビデオの区分が誤っています"); }