-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInvoiceManager.java
More file actions
110 lines (101 loc) · 3.24 KB
/
Copy pathInvoiceManager.java
File metadata and controls
110 lines (101 loc) · 3.24 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
import java.util.ArrayList;
import java.util.Scanner;
/**
* Represents a Invoice Manager in a restaurant.
* @author Tan Zheng Kai
* @version 1.0
* @since 2021-11-13
*/
public class InvoiceManager {
/**
* The GST rate of an invoice manager.
*/
public static double GST = 0.08;
/**
* The list of invoices of this invoice manager.
*/
private ArrayList<Invoice> invoiceList;
/**
* The current invoice of this invoice manager.
*/
private Invoice currentInvoice;
/*
* Creates an Invoice Manager and set currentInvoice to null.
*/
public InvoiceManager() {
this.invoiceList = new ArrayList<Invoice>();
currentInvoice = null;
}
/**
* Calculates base total using the current invoice of this invoice manager.
*/
private double calculateBaseTotal() {
double baseTotal = 0;
for (int i = 0; i<currentInvoice.getOrderDetails().getOrder().getOrderItemList().size(); i++) {
baseTotal += currentInvoice.getOrderDetails().getOrder().getOrderItemList().get(i).getQuantity() * currentInvoice.getOrderDetails().getOrder().getOrderItemList().get(i).getMenuItem().getPrice();
}
return baseTotal;
}
/**
* Calculates the discounted price using the current invoice.
* @param basePrice The base price of the current invoice.
*/
private double getPriceAfterDiscount(double basePrice) {
basePrice *= (1-currentInvoice.getCustomer().getDiscount());
return basePrice;
}
/**
* Calculates the final price using GST of an Invoice Manager.
* @param discountedPrice The final price after factoring GST.
*/
private double getFinalPrice() {
double finalPrice = (1 + GST) * getPriceAfterDiscount(calculateBaseTotal());
return finalPrice;
}
/**
* Prints out an interface to choose an invoice from the list of invoices.
*/
public void chooseInvoice() {
System.out.println("List of Orders, please choose the invoice to be paid for based on index given: ");
for (int i=0; i<invoiceList.size(); i++){
String str = "" + (i+1) + ". ";
System.out.print(str + "Table ");
invoiceList.get(i).print();
}
Scanner sc = new Scanner(System.in);
//NOTE THAT orderId corresponds to position in invoiceList
try {
//assign invoice as currentInvoice
int index = sc.nextInt();
sc.nextLine();
if (index <= 0 || index > this.invoiceList.size()){
throw new ArrayIndexOutOfBoundsException("Please input a valid index from 1 to "+this.invoiceList.size());
}
currentInvoice = invoiceList.get(index-1);
//print invoice here
currentInvoice.printInvoice();
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
System.out.println("program exiting ...");
System.exit(0);
}
}
/**
* Gets the invoice list of this Invoice Manager.
* @return this Invoice Manager's invoice list.
*/
public ArrayList<Invoice> getInvoiceList() {
return this.invoiceList;
}
/**
* Adds an invoice to this Invoice Manager's invoice list.
* @param od Invoice to be added to invoice list.
* @return Invoice to be added to invoice list.
*/
//need a way to add to invoicelist
public Invoice createInvoice(OrderDetails od) {
Invoice temp = new Invoice(od);
invoiceList.add(temp);
return temp;
}
}