-
Notifications
You must be signed in to change notification settings - Fork 685
Expand file tree
/
Copy pathMenuItem.java
More file actions
108 lines (80 loc) · 2.53 KB
/
MenuItem.java
File metadata and controls
108 lines (80 loc) · 2.53 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package org.launchcode;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
public class MenuItem {
private String name;
private String description;
private double price;
private String category;
private final LocalDate dateAdded;
public MenuItem(String name, String description, double price, String category, LocalDate dateAdded) {
this.name = name;
this.description = description;
this.price = price;
this.category = category;
//this.dateAdded = LocalDate.now();
//To test isNew() to be false
//this.dateAdded = LocalDate.parse("2023-09-21");
this.dateAdded = dateAdded;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
//Only getter for dateAdded
public LocalDate getDateAdded() {
return dateAdded;
}
//I Step
//Special Methods
//ToDo: Define custom toString() method
//Format name, description, price and conditional "NEW"
@Override
public String toString() {
String newText = isNew() ? " - NEW! " : "";
return name + newText + "\n" + category + "\n" + description + " | $" + price;
}
//TODO: Define custom equals method
//whether the menuitem is repeated or not
@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);
return this.name.equals(menuItem.getName());
}
// @Override
// public int hashCode() {
// return Objects.hash(name);
// }
//INSTANCE METHODS
//TODO: Define instance method is New()
//return true if item added within last 100 days
boolean isNew() {
LocalDate todayDate = LocalDate.now();
//getDateAdded gets startDate, todayDate-endDate, ChronoUnit.Days-Unit
double daysBetween = getDateAdded().until(todayDate, ChronoUnit.DAYS);
return daysBetween < 100;
}
}