-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRestaurant.java
More file actions
103 lines (96 loc) · 3.91 KB
/
Restaurant.java
File metadata and controls
103 lines (96 loc) · 3.91 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
/**
* Lab 7
*
* Class representing a restaurant. Food orders may be added to a restaurant as Tickets and will be
* stored in some way (how they are stored is up to the subclasses). The order in which Tickets are
* completed is also dependent on the subclass' implementation of the abstract methods.
*
* @author Stephen
* @version 2018-10-10
*
* @modified by Em Evans
* @version 2019-09-27
*/
public abstract class Restaurant
{
/**
*Adds an order to the restaurant.
*The restaurant will keep track of this order until it can be completed by completeOrder()
* @param order
* @return true if the order is successfully added. False otherwise.
*/
public abstract boolean addOrder(Order order);
/**
* Determines the number of orders that have been added to the restaurant that have not been completed.
* i.e. the number of unfulfilled meal orders.
*
* @return The number of orders in the restaurant yet to be completed.
*/
protected abstract int numberRemainingOrder();
/**
* Gets the orders that will next be completed. That is, gets the ticket that would be returned by completeOrder
* without actually completing the ticket.
*
* @return The ticket that will next be completed by the restaurant. null if there are no more tickets to
* be completed.
*/
protected abstract Order checkNextCompletedOrder();
/**
* Uses the abstract methods numberRemainingOrders() and checkNextCompleteOrders()
*
* Gets the current status of the restaurant. Specifically, we get information about the number of orders
* remaining in the restaurant, and the description of the order that will next be completed.
*
* It is recommended that you use String.format()
*
* @return If there are no incomplete orders left in the restaurant, return the String:
* "No orders left."
* Else, return a string of the format:
* "(number of orders in restaurant order list) orders left. Working on: (the toString() of the next order to be completed)"
*/
public String getCurrentStatus()
{
if (numberRemainingOrder() == 0 && checkNextCompletedOrder() == null)
{
return "No orders left.";
}
else
{
return String.format("%d orders left. Working on: %s", numberRemainingOrder(), checkNextCompletedOrder().toString());
}
}
/**
* Completes an order by updating the underlying data structure of the restaurant. Each restaurant uses this
* function to determine the order in which tickets are completed. Once a ticket has been completed, it should
* be considered to be removed from the restaurant. A ticket may not be completed twice. A completed tickets
* symbolizes a meal that has been prepared and delivered to a customer.
*
* @return The next Ticket to be completed.
* null if there are no tickets to be completed.
*/
protected abstract Order completeOrder();
/**
* Uses the overloaded protected completeTicket method.
*
* Completes a ticket and calculates the time it took to complete the ticket. The time to complete a ticket
* is the difference between the time the ticket was completed and the time the ticket was
* (i.e. the ticket's timeOrdered)
*
* @param timeCompleted The time at which the ticket was completed.
* @return A string of the format:
* "It took (time difference) time units to complete the following order: (toString of completed order)"
* if the are no tickets to be created, returns:
* "No orders remain. Could not complete an Ticket."
*/
public String completeOrder(int timeCompleted)
{
if(numberRemainingOrder() != 0)
{
return String.format("It took %d time units to complete the following order: %s", completeOrder().getTimeOrdered() - timeCompleted, completeOrder().toString()); //Finish Implementing later
}
else
{
return "No orders remain. Could not complete an Ticket.";
}
}
}