-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrder.java
More file actions
164 lines (152 loc) · 4.7 KB
/
Copy pathOrder.java
File metadata and controls
164 lines (152 loc) · 4.7 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import java.util.Scanner;
import java.util.ArrayList;
/**
* Represents an Order in a restaurant.
* @author Tan Zheng Kai
* @version 2.0
* @since 2021-11-13
*/
public class Order {
private ArrayList<OrderItem> orderItemList;
private Staff s;
private OrderDetails orderDetails;
/**
* Creates a new order after taking in name of staff.
*/
public Order() {
this.orderItemList = new ArrayList<OrderItem>();
RestaurantApp.globalStaffManager.displayList();
Scanner sc = new Scanner(System.in);
try {
System.out.println("Who's taking this order?");
int choice = sc.nextInt();
sc.nextLine();
if (choice <= 0 || choice > RestaurantApp.globalStaffManager.getSizeOfStaffList()){
throw new ArrayIndexOutOfBoundsException("Please input a valid index from 1 to "+RestaurantApp.globalStaffManager.getSizeOfStaffList());
}
this.s = RestaurantApp.globalStaffManager.getStaff(choice-1);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
System.out.println("program exiting ...");
System.exit(0);
}
this.orderDetails = new OrderDetails(this);
}
/**
* Creates a new order item into the order list.
*/
public void makeNewOrder(){
Scanner sc = new Scanner(System.in);
int createChoice = 0;
while (createChoice < 2){
System.out.println("What would you like to do?");
System.out.println("1. add order items 2. quit");
createChoice = sc.nextInt();
sc.nextLine();
if (createChoice == 1){
this.addToOrder();
}
}
}
/**
* Adds or remove an order item into the list.
*/
public void updateOrder(){
Scanner sc = new Scanner(System.in);
System.out.println("What would you like to do?");
System.out.println("1. add order item 2. remove order item");
int choice = sc.nextInt();
sc.nextLine();
if (choice == 1) this.addToOrder();
else this.deleteFromOrder();
}
/**
* Calls creates order item and adds it into the order item list.
*/
public void addToOrder() { //calls createOrderItem from OrderItem and adds it to orderItemList
OrderItem temp = new OrderItem();
temp.createOrderItem();
this.orderItemList.add(temp);
}
/**
* Deletes an order item from order item list.
*/
public void deleteFromOrder() {
Scanner sc = new Scanner(System.in);
this.printOrder();
try {
System.out.println("Which order item would you like to delete?");
int orderItemIndex = sc.nextInt();
sc.nextLine();
if (orderItemIndex <= 0 || orderItemIndex > this.orderItemList.size()){
throw new ArrayIndexOutOfBoundsException("Please input a valid index from 1 to "+this.orderItemList.size());
}
this.orderItemList.remove(orderItemIndex - 1); //delete the index - 1 orderItem from this order
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
System.out.println("program exiting ...");
System.exit(0);
}
}
/**
* Calculates the base price of all order items.
* @return the base price of all order items.
*/
public double calculateBasePrice() {
int orderSize = this.orderItemList.size();
double basePrice = 0;
for(int i = 0; i<orderSize; i++){
basePrice += this.orderItemList.get(i).calculatePrice(); //iterates list and adds to basePrice the orderItems in order
}
return basePrice;
}
/**
* Prints out every order item in this order.
*/
public void printOrder() {
int orderSize = this.orderItemList.size();
System.out.println("Staff Name: " + this.s.getName());//should this be a print function of staff?
System.out.println("----------------------------------------------");
for(int i = 0; i<orderSize; i++){
System.out.print((i+1) + ". ");
this.orderItemList.get(i).printOrderItem();
System.out.println("----------------------------------------------");
}
System.out.println();
}
/**
* Gets order details of this order.
* @return the order details of this Order.
*/
public OrderDetails getOrderDetails() {
return this.orderDetails;
}
/**
* Changes order details of this order.
* @param orderDetails The order details of this order
*/
public void setOrderDetails(OrderDetails orderDetails) {
this.orderDetails = orderDetails;
}
/**
* Gets the staff of this order.
* @return this order's staff.
*/
public Staff getStaff(){
return this.s;
}
/**
* Changes the staff of this order.
* @param staff This order's staff.
*/
public void setStaff(Staff staff){
this.s = staff;
}
/**
* Gets the order item list of this order.
* @return the order item list of this order.
*/
public ArrayList<OrderItem> getOrderItemList() {
return this.orderItemList;
}
}