-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOrder.java
More file actions
75 lines (64 loc) · 1.5 KB
/
Order.java
File metadata and controls
75 lines (64 loc) · 1.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
import java.util.Date;
import java.sql.Timestamp;
import java.text.NumberFormat;
import java.util.ArrayList;
/**
* Order aggregates Items in a particular order. It additionally provides total
* price and logWrite String format
*
* @author Chae Jubb
* @version 1.0
*
*/
public class Order {
private ArrayList<Item> foodList;
private double totalPrice;
/**
* Constructor. Defaults to no items at zero price
*/
public Order() {
this.foodList = new ArrayList<Item>();
this.totalPrice = 0;
}
/**
* Adds item to order. Updates total price
*
* @param itm
* Item to be added to Order
*/
public void addItem(Item itm) {
this.foodList.add(itm);
this.totalPrice += itm.getPrice();
}
/**
* Resets order to defaults (Blank order and no price)
*/
public void clearItems() {
this.foodList.clear();
this.totalPrice = 0;
}
/**
* Formats a string representation of the Item array in such a way that it
* is readable in a logfile.
*
* @return String to be written to log file
*/
public String logWrite() {
String output = "";
for (Item itm : this.foodList) {
output += itm.toString() + "\n";
}
NumberFormat formatter = NumberFormat.getCurrencyInstance();
output += "\n TOTAL: " + formatter.format(this.totalPrice);
output += "\n" + new Timestamp(new Date().getTime()) + "\n \n";
return output;
}
/**
* Getter method for running total price
*
* @return running total price
*/
public double getTotalPrice() {
return this.totalPrice;
}
}