-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoffeeOrder.java
More file actions
57 lines (48 loc) · 1.64 KB
/
CoffeeOrder.java
File metadata and controls
57 lines (48 loc) · 1.64 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
/*
* Author: Sam Braude (Red ID: 826984009)
* Intermediate Computer Programming Lab (CS 160L)
* Erin Ratelle
* June 28, 2023
*/
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class CoffeeOrder {
private List<Coffee> coffees;
private LocalDateTime orderDate;
public CoffeeOrder() {
coffees = new ArrayList<Coffee>();
orderDate = LocalDateTime.now();
}
public CoffeeOrder(Coffee coffee) {
this();
addCoffee(coffee);
}
public CoffeeOrder(LocalDateTime orderDate) {
coffees = new ArrayList<Coffee>();
this.orderDate = orderDate;
}
public void addCoffee(Coffee c) {
coffees.add(c);
}
public List<Coffee> getCoffees() { return coffees; }
public LocalDateTime getOrderDate() { return orderDate; }
public double getTotal() {
double total = 0;
for (Coffee coffee : coffees) {
total += coffee.getCost();
}
return total;
}
public String printOrder() {
StringBuilder order = new StringBuilder("ORDER RECEIPT\n");
order.append(String.format("Timestamp: %s%n", orderDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd hh:mma"))));
for (int i = 0; i < coffees.size(); i++) {
Coffee coffee = coffees.get(i);
order.append(String.format("Item %d: %s - %.2f%n", i + 1, coffee.printCoffee(), coffee.getCost()));
}
order.append(String.format("TOTAL = %.2f%n", getTotal()));
return order.toString();
}
}