Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/video/domain/Movie.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,4 +29,17 @@ public void setPriceType(PriceType priceType) {
public String getTitle() {
return title;
}

public int amount(int daysRented) {
switch (priceType) {
case REGULAR:
return regularPrice.amount(daysRented);
case NEW_RELEASE:
return newReleasePrice.amount(daysRented);
case CHILDREN:
return childrenPrice.amount(daysRented);
default:
throw new RuntimeException("ビデオの区分が誤っています");
}
}
}
22 changes: 2 additions & 20 deletions src/main/java/video/domain/rental/Rental.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand Down