diff --git a/src/main/java/video/domain/price/ChildrenPrice.java b/src/main/java/video/domain/price/ChildrenPrice.java new file mode 100644 index 0000000..7301e5f --- /dev/null +++ b/src/main/java/video/domain/price/ChildrenPrice.java @@ -0,0 +1,8 @@ +package video.domain.price; + +public class ChildrenPrice implements Price { + public int amount(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/price/NewReleasePrice.java b/src/main/java/video/domain/price/NewReleasePrice.java new file mode 100644 index 0000000..2631a55 --- /dev/null +++ b/src/main/java/video/domain/price/NewReleasePrice.java @@ -0,0 +1,8 @@ +package video.domain.price; + +public class NewReleasePrice implements Price { + + public int amount(int daysRented) { + return daysRented * 300; + } +} \ No newline at end of file diff --git a/src/main/java/video/domain/price/Price.java b/src/main/java/video/domain/price/Price.java new file mode 100644 index 0000000..c4a372a --- /dev/null +++ b/src/main/java/video/domain/price/Price.java @@ -0,0 +1,5 @@ +package video.domain.price; + +public interface Price { + int amount(int daysRented); +} diff --git a/src/main/java/video/domain/price/RegularPrice.java b/src/main/java/video/domain/price/RegularPrice.java new file mode 100644 index 0000000..cc8b589 --- /dev/null +++ b/src/main/java/video/domain/price/RegularPrice.java @@ -0,0 +1,8 @@ +package video.domain.price; + +public class RegularPrice implements Price { + public int amount(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/ChildrenPrice.java b/src/main/java/video/domain/rental/ChildrenPrice.java deleted file mode 100644 index 8c8c32a..0000000 --- a/src/main/java/video/domain/rental/ChildrenPrice.java +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 0bc61e3..0000000 --- a/src/main/java/video/domain/rental/NewReleasePrice.java +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index dcb05d0..0000000 --- a/src/main/java/video/domain/rental/RegularPrice.java +++ /dev/null @@ -1,11 +0,0 @@ -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 55bf1c6..72c1e53 100644 --- a/src/main/java/video/domain/rental/Rental.java +++ b/src/main/java/video/domain/rental/Rental.java @@ -2,6 +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(); @@ -28,11 +31,11 @@ public int amount() { int daysRented = getDaysRented(); switch (getMovie().getPriceType()) { case REGULAR: - return regularPrice.price(daysRented); + return regularPrice.amount(daysRented); case NEW_RELEASE: - return newReleasePrice.price(daysRented); + return newReleasePrice.amount(daysRented); case CHILDREN: - return childrenPrice.price(daysRented); + return childrenPrice.amount(daysRented); default: throw new RuntimeException("ビデオの区分が誤っています"); }