-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
95 lines (86 loc) · 2.04 KB
/
Order.java
File metadata and controls
95 lines (86 loc) · 2.04 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
import java.util.Date;
/**
* Lab 7
*
* Class to represent a meal order submitted to a restaurant. Orders have a description (i.e. what food was
* ordered) as well as a timeOrdered (i.e. when the food was ordered/when the ticket was created) and a
* server (i.e. a number indicating which server is assigned to.
*
* @author Stephen
* @version 2018-02-26
*
* @modified by Em Evans
* @version 2019-09-27
*/
public class Order implements Comparable<Order>
{
/**
* The description of the order. i.e. what food was ordered.
*/
private String description;
/**
* The time (represented as an int) that the customers ordered it.
*/
private int timeOrdered;
/**
* Create an Order. Set all attributes.
*
* @param description
* @param timeOrdered
*/
public Order(String description, int timeOrdered)
{
this.description = description;
this.timeOrdered = timeOrdered;
}
/**
* @return description
*/
public String getDescription()
{
return this.description;
}
/**
* @return timeOrdered
*/
public int getTimeOrdered()
{
return this.timeOrdered;
}
/**
* toString override.
* @return a String of the format "Description: <<description>>"
**/
@Override
public String toString()
{
return String.format("Description: %s", getDescription());
}
/**
* Comparison override. Comparison for Orders sorts the orders in order of when the order
* was created.
*
* @param other The other ticket to compare this one to.
* @return -1 if this ticket was created before the other ticket
* 0 if this ticket was created at the same time as the other ticket
* 1 if this ticket was created after the other ticket
*/
@Override
public int compareTo(Order order)
{
int position = 0;
if(this.getTimeOrdered() < order.getTimeOrdered())
{
return -1;
}
else if(this.getTimeOrdered() == order.getTimeOrdered())
{
return 0;
}
else if(this.getTimeOrdered() > order.getTimeOrdered())
{
return 1;
}
return position;
}
}