-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer.java
72 lines (65 loc) · 2.19 KB
/
Customer.java
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
package de.bitbizeps.MovieStore;
import java.lang.*;
import java.util.*;
class Customer {
private String name;
private Vector rentals = new Vector();
public Customer (String newname){
name = newname;
};
public void addRental(Rental arg) {
rentals.addElement(arg);
};
public String getName (){
return name;
};
public String statement() {
Enumeration rentals = this.rentals.elements();
String result = "Rental Record for " + getName() + "\n";
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += "\t" + each.getMovie().getTitle()+ "\t" +
String.valueOf(each.getCharge()) + "\n";
}
result += "Amount owed is " +
String.valueOf(getTotalCharge()) + "\n";
result += "You earned " +
String.valueOf(getTotalFrequentRenterPoints()) +
" frequent renter points";
return result;
}
private int getTotalFrequentRenterPoints(){
int result = 0;
Enumeration rentals = this.rentals.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getFrequentRenterPoints();
}
return result;
}
private double getTotalCharge() {
double result = 0;
Enumeration rentals = this.rentals.elements();
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getCharge();
}
return result;
}
//new method for generating an HTML version of the statement String
public String htmlStatement() {
Enumeration rentals = this.rentals.elements();
String result = "<H1>Rentals for <EM>" + getName() + "</EM></H1><P>\n";
while (rentals.hasMoreElements()) {
Rental each = (Rental) rentals.nextElement();
result += each.getMovie().getTitle()+ ": " +
String.valueOf(each.getCharge()) + "<BR>\n";
}
result += "<P>You owe <EM>" + String.valueOf(getTotalCharge()) +
"</EM><P>\n";
result += "On this rental you earned <EM>" +
String.valueOf(getTotalFrequentRenterPoints()) +
"</EM> frequent renter points<P>";
return result;
}
}