-
Notifications
You must be signed in to change notification settings - Fork 686
Expand file tree
/
Copy pathMenuItem.java
More file actions
80 lines (63 loc) · 1.93 KB
/
MenuItem.java
File metadata and controls
80 lines (63 loc) · 1.93 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
77
78
79
package org.launchcode;
import java.time.LocalDate;
import java.util.Objects;
import java.time.temporal.ChronoUnit;
public class MenuItem {
private String name;
private double price;
private String description;
private String category;
private LocalDate dateAdded;
private boolean isNew;
public MenuItem(String name, double price, String description, String category, LocalDate dateAdded, boolean isNew) {
this.name = name;
this.price = price;
this.description = description;
this.category = category;
this.dateAdded = dateAdded;
this.isNew = isNew;
}
public void setPrice(double price) {
this.price = price;
}
public void setDescription(String description) {
this.description = description;
}
public void setCategory(String category) {
this.category = category;
}
public void setNew(boolean aNew) {
this.isNew = aNew;
}
public boolean getNew() {
return isNew;
}
public void setDateAdded(LocalDate dateAdded) {this.dateAdded = dateAdded;}
public void calculateIsNew() {
LocalDate now = LocalDate.now();
long difference = ChronoUnit.DAYS.between(this.dateAdded, now);
if (difference < 31) {
this.setNew(true);
} else {
this.setNew(false);
}
}
@Override
public String toString() {
return name + "\n" +
" price= $" + price + "\n" +
" description= " + description + "\n" +
" category= " + category + "\n" + "\n";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MenuItem menuItem = (MenuItem) o;
return Objects.equals(name, menuItem.name);
}
@Override
public int hashCode() {
return Objects.hash(name);
}
}