-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItem.java
More file actions
45 lines (45 loc) · 1.13 KB
/
Item.java
File metadata and controls
45 lines (45 loc) · 1.13 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
public class Item{
private String name;
private double listCost;
private User owner;
private boolean forSale;
public Item(String name, double listCost, User owner, boolean forSale){
this.name = name;
this.listCost = Math.round(100*listCost)/100.0;
this.owner = owner;
this.forSale = forSale;
}
public String getName(){
return name;
}
public double getListCost(){
return listCost;
}
public User getOwner(){
return owner;
}
public boolean getForSale(){
return forSale;
}
public void setOwner(User owner){
this.owner = owner;
}
public void setListCost(double listCost){
this.listCost = listCost;
}
public void toggleForSale(){
if(forSale == true){
forSale = false;
} else{
forSale = true;
}
}
public void purchaseItem(User person, double money){
person.updateBalance(-money);
setOwner(person);
toggleForSale();
}
public String toString(){
return name + " ($" + listCost + " - " + owner.getName() + ")";
}
}