-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.java
More file actions
160 lines (145 loc) · 4.66 KB
/
Transaction.java
File metadata and controls
160 lines (145 loc) · 4.66 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
import java.util.*;
import java.text.SimpleDateFormat;
public class Transaction
{
private String userEmail;
private String transactionId;
private ArrayList<String[]> purchaseList;
private Calendar date;
private double totalPrice;
/**
* A default constructor for objects of class Transaction.
*/
public Transaction()
{
userEmail = "";
transactionId = "";
purchaseList = new ArrayList<String[]>();
date = Calendar.getInstance();
totalPrice = 0;
}
/**
* A constructor for objects of class Transaction.
*/
public Transaction(String newUserEmail, String newTransactionId, ArrayList<String[]> newPurchaseList, Calendar newDate, double newTotalPrice)
{
userEmail = newUserEmail;
transactionId = newTransactionId;
purchaseList = newPurchaseList;
date = newDate;
totalPrice = newTotalPrice;
}
/**
* Create a calToStr method to get date.
*/
private String calToStr()
{
SimpleDateFormat sdf = new SimpleDateFormat("hh:mm:ss dd/MM/yyyy");
String calStr = sdf.format(date.getTime());
return calStr;
}
/**
* Create a displayTransaction method to display transaction details.
*/
public void displayTransaction()
{
String inventoryOption = new String();
SimpleDateFormat df = new SimpleDateFormat("hh:mm:ss dd/MM/yyyy");
System.out.println("Transaction id: " + transactionId);
System.out.println("Buyer: " + userEmail + ", order time: " + df.format(date.getTime()) + ", total price: AU$" + totalPrice);
System.out.println("There are " + purchaseList.size() + " items in the transaction.");
for (int index = 0; index < purchaseList.size(); index++)
{
if (purchaseList.get(index)[3].toUpperCase().equals("BAG") || purchaseList.get(index)[3].toUpperCase().equals("KG") ||
purchaseList.get(index)[3].toUpperCase().equals("BUNCH"))
inventoryOption = "kg";
else
inventoryOption = "wholes";
System.out.println(index + 1 + ". " + "Product ID: " + purchaseList.get(index)[0] + ", Product name: " + purchaseList.get(index)[1]);
System.out.println(purchaseList.get(index)[2] + " " + purchaseList.get(index)[3] + " for AU$" + purchaseList.get(index)[4] + "(" + purchaseList.get(index)[5] + " " + inventoryOption + ")");
}
}
/**
* Create a getDate method to get Date.
*/
public Calendar getDate()
{
return date;
}
/**
* Create a getDetail method to get transaction details.
*/
public String getDetail()
{
String purchase = "";
int size = purchaseList.size();
for (int i = 0;i < size;i++)
purchase = purchase + "," + purchaseList.get(i)[0] + "," + purchaseList.get(i)[1] + "," + purchaseList.get(i)[2] + ","
+ purchaseList.get(i)[3] + "," + purchaseList.get(i)[4] + "," + purchaseList.get(i)[5];
String detail = userEmail + "," + transactionId + "," + calToStr() + "," + String.valueOf(totalPrice) + purchase;
return detail;
}
/**
* Create a getPurchaseList method to get Purchase List.
*/
public ArrayList<String[]> getPurchaseList()
{
return purchaseList;
}
/**
* Create a getUserEmail method to get User Email.
*/
public String getUserEmail()
{
return userEmail;
}
/**
* Create a getTransactionId method to get Transaction Id.
*/
public String getTransactionId()
{
return transactionId;
}
/**
* Create a getTotalPrice method to get Total Price.
*/
public double getTotalPrice()
{
return totalPrice;
}
/**
* Create a getDate method to set Date.
*/
public void setDate(Calendar newDate)
{
date = newDate;
}
/**
* Create a setPurchaseList method to set Purchase List.
*/
public void setPurchaseList(ArrayList<String[]> newPurchaseList)
{
purchaseList = newPurchaseList;
}
/**
* Create a setUserEmail method to set User Email.
*/
public void setUserEmail(String newUserEmail)
{
userEmail = newUserEmail;
}
/**
* Create a setTransactionId method to set Transaction Id.
*/
public void setTransactionId(String newTransactionId)
{
transactionId = newTransactionId;
}
/**
* Create a setTotalPrice method to est Total Price.
*/
public void setTotalPrice(double newTotalPrice)
{
totalPrice = newTotalPrice;
}
}