-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.java
More file actions
98 lines (77 loc) · 2.5 KB
/
Order.java
File metadata and controls
98 lines (77 loc) · 2.5 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
/*
Name: Jacob Kerames
Project Name: CSC400 - Portfolio Project
Project Purpose: Handle orders for an online retailer
Algorithm Used: A queue is used to store the orders, and the quick sort and
comparators are used to sort the arrays in descending order by name and order
number.
Program Inputs: The program allows for input of customer last names, order numbers,
and total costs. It also requires input of a choice for user menu interaction.
Program Outputs: The program outputs the orders in the queue, twice. Once sorted
by the customers' last names and the other sorted by order number.
Program Limitations: The program does not have features for interacting with other
systems, like inventory or shipping systems.
Program Errors: The program contains error handling and input validation for
invalid input.
*/
import java.util.Queue;
import java.util.LinkedList;
class Order {
// Queue to hold the orders
private Queue<Order> orders;
// Queue constructor
public Order() {
orders = new LinkedList<>();
}
// Order constructor
public Order(String lastName, int orderNumber, double totalCost) {
this.lastName = lastName;
this.orderNumber = orderNumber;
this.totalCost = totalCost;
}
// Add an order to the queue
public void addOrder(String lastName, int orderNumber, double totalCost) {
orders.add(new Order(lastName, orderNumber, totalCost));
}
// Remove the order from the queue
public void removeOrder(int orderNumber) {
for (Order order : orders) {
if (order.getOrderNumber() == orderNumber) {
orders.remove(order);
break;
}
}
}
// Get the queue of orders
public Queue<Order> getOrders() {
return orders;
}
// Order detail fields
private String lastName;
private int orderNumber;
private double totalCost;
// Get last name
public String getLastName() {
return lastName;
}
// Get order number
public int getOrderNumber() {
return orderNumber;
}
// Get total cost
public double getTotalCost() {
return totalCost;
}
// Check if an order number exists in the queue
public boolean checkOrderNumberExists(int orderNumber) {
if (orders.isEmpty()) {
return false;
}
for (Order order : orders) {
if (order.getOrderNumber() == orderNumber) {
return true;
}
}
return false;
}
}