-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
76 lines (64 loc) · 1.49 KB
/
Customer.java
File metadata and controls
76 lines (64 loc) · 1.49 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
//Customer.java
//created by :Daniel Myers
import java.util.*;
import java.io.*;
public class Customer implements PurchaseHistory, Serializable{
private static final long serialVersionUID = 5944615789089180687L;
private String name;
private Address address;
private int accountNumber;
private ArrayList<Product> productList = new ArrayList<Product>();
private int music;
private int app;
public Customer(String n, Address a, int aN){
setName(n);
setAddress(a);
setAccountNumber(aN);
}
public void setName(String n){
name = n;
}
public String getName(){
return name;
}
public void setAddress(Address a){
address = a;
}
public Address getAddress(){
return address;
}
public void setAccountNumber(int aN){
accountNumber = aN;
}
public int getAccountNumber(){
return accountNumber;
}
public void addToProductList(Product p){
productList.add(p);
}
public ArrayList<Product> getProductList(){
return this.productList;
}
public double calculateCharge(){
double charge = 0.0;
for(Product p: productList){
if(p.getClass().getName().equals("Music")){
charge += ((Music)p).getNumberOfSongsPurchased() * p.getPrice();
music++;
}
else {
charge += p.getPrice();
app++;
}
}
return charge;
}
public String createHistory(){
String output = "";
output = String.format("%d Music products %d Apps $%.2f", music, app, calculateCharge());
return output;
}
public String toString(){
return (name + " " + createHistory());
}
}