1 public class Movie implements PriceParams
2 {
3 private String _title;
4 private Price _price;
5
6 public Movie(String title, int priceCode)
7 {
8 _title = title;
9 _price = Price.getInstance(priceCode);
10 }
11
12 public int getPriceCode()
13 {
14 return _price.getPriceCode();
15 }
16
17 public void setPriceCode(int priceCode)
18 {
19 _price = Price.getInstance(priceCode);
20 }
21
22 public String getTitle()
23 {
24 return _title;
25 }
26
27 public double getCharge(int daysRented)
28 {
29 double result = 0;
30 switch (getPriceCode()) {
31 case REGULAR:
32 result += 2;
33 if (daysRented > 2)
34 result += (daysRented - 2) * 1.5;
35 break;
36 case NEW_RELEASE:
37 result += daysRented * 3;
38 break;
39 case CHILDRENS:
40 result += 1.5;
41 if (daysRented > 3)
42 result += (daysRented - 3) * 1.5;
43 break;
44 }
45 return result;
46 }
47
48 public int getFrequentRenterPoints(int daysRented)
49 {
50 if(getPriceCode() == NEW_RELEASE && daysRented > 1)
51 return 2;
52 else
53 return 1;
54 }
55 }