You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Movie.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. public class Movie {
  2. public static final int CHILDRENS = 2;
  3. public static final int REGULAR = 0;
  4. public static final int NEW_RELEASE = 1;
  5. public static final int STUDENTS = 3;
  6. private final String title;
  7. private Price price;
  8. public Movie( String title, int priceCode ) {
  9. this.title = title;
  10. setPriceCode( priceCode );
  11. }
  12. public String getTitle() {
  13. return title;
  14. }
  15. public int getPriceCode() {
  16. return price.getPriceCode();
  17. }
  18. public void setPriceCode( int priceCode ) {
  19. switch( priceCode ) {
  20. case Movie.REGULAR:
  21. this.price = new RegularPrice();
  22. break;
  23. case Movie.CHILDRENS:
  24. this.price = new ChildrensPrice();
  25. break;
  26. case Movie.NEW_RELEASE:
  27. this.price = new NewReleasePrice();
  28. break;
  29. case Movie.STUDENTS:
  30. this.price = new StudentsPrice();
  31. break;
  32. default:
  33. throw new IllegalArgumentException("Incorrect Price Code");
  34. }
  35. }
  36. public double calculateFee ( int daysRented) {
  37. return price.getFee( daysRented);
  38. }
  39. public int calculateBonus( int daysRented) {
  40. return price.getBonus( daysRented );
  41. }
  42. /* public double calculateFee (int daysRented) {
  43. double thisAmount = 0;
  44. // determine amounts for each line
  45. switch( getPriceCode() ) {
  46. case Movie.REGULAR:
  47. thisAmount += 2;
  48. if( daysRented > 2 )
  49. thisAmount += ( daysRented - 2 ) * 1.5;
  50. break;
  51. case Movie.NEW_RELEASE:
  52. thisAmount += daysRented * 3;
  53. break;
  54. case Movie.CHILDRENS:
  55. thisAmount += 1.5;
  56. if( daysRented > 3 )
  57. thisAmount += ( daysRented - 3 ) * 1.5;
  58. break;
  59. }
  60. return thisAmount;
  61. }
  62. */
  63. /* public int calculateBonus (int daysRented){
  64. int frequentRenterPoints = 1;
  65. // add bonus for a two day new release rental
  66. if( ( getPriceCode() == Movie.NEW_RELEASE ) && daysRented > 1 )
  67. frequentRenterPoints++;
  68. return frequentRenterPoints;
  69. }
  70. */
  71. }