public class Movie { public static final int CHILDRENS = 2; public static final int REGULAR = 0; public static final int NEW_RELEASE = 1; public static final int STUDENTS = 3; private final String title; private Price price; public Movie( String title, int priceCode ) { this.title = title; setPriceCode( priceCode ); } public String getTitle() { return title; } public int getPriceCode() { return price.getPriceCode(); } public void setPriceCode( int priceCode ) { switch( priceCode ) { case Movie.REGULAR: this.price = new RegularPrice(); break; case Movie.CHILDRENS: this.price = new ChildrensPrice(); break; case Movie.NEW_RELEASE: this.price = new NewReleasePrice(); break; case Movie.STUDENTS: this.price = new StudentsPrice(); break; default: throw new IllegalArgumentException("Incorrect Price Code"); } } public double calculateFee ( int daysRented) { return price.getFee( daysRented); } public int calculateBonus( int daysRented) { return price.getBonus( daysRented ); } /* public double calculateFee (int daysRented) { double thisAmount = 0; // determine amounts for each line switch( getPriceCode() ) { case Movie.REGULAR: thisAmount += 2; if( daysRented > 2 ) thisAmount += ( daysRented - 2 ) * 1.5; break; case Movie.NEW_RELEASE: thisAmount += daysRented * 3; break; case Movie.CHILDRENS: thisAmount += 1.5; if( daysRented > 3 ) thisAmount += ( daysRented - 3 ) * 1.5; break; } return thisAmount; } */ /* public int calculateBonus (int daysRented){ int frequentRenterPoints = 1; // add bonus for a two day new release rental if( ( getPriceCode() == Movie.NEW_RELEASE ) && daysRented > 1 ) frequentRenterPoints++; return frequentRenterPoints; } */ }