-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCustomer.java
More file actions
56 lines (43 loc) · 982 Bytes
/
Customer.java
File metadata and controls
56 lines (43 loc) · 982 Bytes
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
package assignment1;
public class Customer {
//private fields
private String name;//customer's name
private int balance = 0;
private Basket buy;
//constructors
public Customer(String n, int ib) {
buy = new Basket();
this.name = n;
this.balance = ib;
}
//get methods
public String getName() {
return this.name;
}
public int getBalance() {
return this.balance;
}
public Basket getBasket() {
return this.buy;
}
public int addFunds(int ba) {
if (ba < 0)
throw new IllegalArgumentException("input funds cannot be negative");
else
balance += ba;
return balance;
}
public void addToBasket(MarketProduct p) {
buy.add(p);
}
public boolean removeFromBasket(MarketProduct p) {
return buy.remove(p);
}
public String checkOut() {
if (balance < this.buy.getTotalCost())
throw new IllegalStateException("customer balance not enough");
else
balance -= this.buy.getTotalCost();
return this.buy.toString();
}
}