-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomer.java
More file actions
76 lines (62 loc) · 2.14 KB
/
Copy pathCustomer.java
File metadata and controls
76 lines (62 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package restructure.old;
import java.util.Enumeration;
import java.util.Vector;
/**
* 消费者
*
* @author vayi
* @date 2018/7/30
* @since 0.0.1
*/
public class Customer {
private Vector rentals = new Vector();
private String name;
public Customer(String name) {
super();
this.name = name;
}
public void addRental(Rental arg) {
rentals.addElement(arg);
}
public String getName() {
return name;
}
public String statement() {
double totalAmount = 0;
int frequentRenterPoints = 0;
Enumeration rentalss = rentals.elements();
String result = "RentalNew Record for" + " " + getName() + "\n";
while (rentalss.hasMoreElements()) {
double thisAmount = 0;
Rental each = (Rental) rentalss.nextElement();
switch (each.getMovie().getPriceCode()) {
case Movie.regular:
thisAmount += 2;
if (each.getDayRented() > 2)
thisAmount += (each.getDayRented() - 2) * 1.5;
break;
case Movie.new_release:
thisAmount += each.getDayRented() * 3;
break;
case Movie.childrens:
thisAmount += 1.5;
if (each.getDayRented() > 3)
thisAmount += (each.getDayRented() - 3) * 1.5;
break;
}
//积分 每借一张加1个积分
frequentRenterPoints++;
//积分累加条件 新版本的片子,借的时间大于1天
if ((each.getMovie().getPriceCode() == Movie.new_release) && each.getDayRented() > 1) {
frequentRenterPoints++;
}
result += "\t" + each.getMovie().getTitle() + "\t"
+ String.valueOf(thisAmount) + "\n";
totalAmount += thisAmount;
}
result += "Amount owed is " + String.valueOf(totalAmount) + "\n";
result += "You earned " + String.valueOf(frequentRenterPoints) + " "
+ "frequent renter points";
return result;
}
}