-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathManagerFrame.java
More file actions
155 lines (146 loc) · 6.97 KB
/
Copy pathManagerFrame.java
File metadata and controls
155 lines (146 loc) · 6.97 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
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.*;
// GUI class that produces a frame that the manager can navigate from to perform different actions
public class ManagerFrame extends JFrame implements ActionListener {
private Bank bank;
private Login login;
private JPanel panel = new JPanel(new GridLayout(3, 1));
private JLabel messageLabel = new JLabel("Service Select: ");
private JButton registerCustomer = new JButton("Register a New Customer");
private JButton generateReport = new JButton("Generate Report");
private JButton checkCustomer = new JButton("Check on a Customer");
private JButton adjustStocks = new JButton("Adjust Stocks");
private JButton advanceDate = new JButton("Advance Date");
private JButton allReports = new JButton("Transaction History");
private JButton logOut = new JButton("Log Out");
public ManagerFrame(Bank bank, Login login) {
this.bank = bank;
this.login = login;
panel.add(messageLabel);
// panel.add(registerCustomer);
panel.add(generateReport);
panel.add(checkCustomer);
panel.add(adjustStocks);
panel.add(advanceDate);
panel.add(allReports);
panel.add(logOut);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
registerCustomer.addActionListener(this);
generateReport.addActionListener(this);
checkCustomer.addActionListener(this);
adjustStocks.addActionListener(this);
logOut.addActionListener(this);
advanceDate.addActionListener(this);
allReports.addActionListener(this);
add(panel, BorderLayout.CENTER);
setTitle("Manager Login" + " - " + Bank.date);
setSize(600, 150);
setVisible(true);
}
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() == registerCustomer) { // done!
CustomerRegistrationFrame frame = new CustomerRegistrationFrame(bank);
} else if (ae.getSource() == generateReport) { // done!
generateBankReport(1);
}else if (ae.getSource() == checkCustomer) {
this.dispose();// done!
CustomerInfoFrame frame = new CustomerInfoFrame(this,bank);
} else if (ae.getSource() == adjustStocks) {
this.dispose();
ManagerStockFrame frame = new ManagerStockFrame(this,bank);
} else if (ae.getSource() == logOut) {
JOptionPane.showMessageDialog(rootPane, "You have logged out.");
this.dispose();
login.setTitle("Bank Login" + " - " + Bank.date);
login.setVisible(true);
} else if (ae.getSource() == advanceDate) {
ArrayList<Deposit> interestPaid = new ArrayList<Deposit>();
ArrayList<Currency> loans = new ArrayList<Currency>();
for (Customer customer : bank.getCustomers()) {
for (Account account : customer.getAccounts()) {
if (account instanceof SavingsAccount) {
if (account.getAmount().convertTo("dollar").getValue() > 2500) {
Currency interest = ((SavingsAccount) account).accumulateInterest();
Deposit dep = new Deposit(account,customer, interest,Bank.date);
account.deposit(dep);
interestPaid.add(dep);
}
} else if (account instanceof LoanAccount) {
for (Loan loan : ((LoanAccount) account).getLoans()) {
loans.add(loan.accumulateInterest());
}
}
}
}
if (interestPaid.size() == 0) {
JOptionPane.showMessageDialog(rootPane, "No interest was paid today to your customers! Wealthy!");
} else {
String msg = "Sad! You had to pay interest to your customers!\n\n";
for (Deposit deposit : interestPaid) {
msg += deposit.getUser().getUsername() + ": Savings Account (" + deposit.getAccount().getID().toString() + ") received " + deposit.getValue().toString() + " (" + deposit.getAccount().getAmount().toString() + ").\n";
}
JOptionPane.showMessageDialog(rootPane, msg);
}
if (loans.size() == 0){
JOptionPane.showMessageDialog(rootPane, "You did not receive any interest from customers");
} else {
String msg = "You accrued the following from different loans! Money!\n\n";
Double value = 0.0;
for (Currency loan : loans) {
msg += loan.toString() + "\n";
value += loan.convertTo("dollar").getValue();
}
JOptionPane.showMessageDialog(rootPane, msg + "You gained " + new Dollar(value).toString() + " in total.");
}
generateBankReport(0);
Bank.pushDate();
JOptionPane.showMessageDialog(rootPane, "Date has been advanced forward to " + Bank.date.toString());
setTitle("Manager Login" + " - " + Bank.date);
} else if (ae.getSource() == allReports) {
generateBankReport(3);
}
}
public void generateBankReport(int MODE) {
StringBuilder str = new StringBuilder();
switch (MODE) {
case 0:
str.append("END OF DATE REPORT OF ALL TRANSACTIONS FOR: " + Bank.date.toString() + "\n");
break;
case 1:
str.append("MID-DAY BANK REPORT OF ALL TRANSACTIONS FOR: " + Bank.date.toString() + "\n");
break;
case 3:
str.append("VIEWING TRANSACTION HISTORY PER CUSTOMER\n");
break;
}
str.append("Number of Customers: " + bank.getCustomers().size() + "\n\n");
for (Customer c : bank.getCustomers()) {
int count = 0;
str.append("Customer: " + c.getUsername() + "\n");
for (Transaction t : c.getAllTransactions()) {
if ((t.getDate().getTime() == Bank.date.getTime())) {
str.append(t.toString() + "\n");
count += 1;
} else if (MODE == 3) {
str.append(t.toString() + "\n");
count += 1;
}
}
if (count == 0) {
str.append("no transactions for the current date");
}
str.append("\n\n");
}
PersistanceHandler p = new PersistanceHandler();
p.persistReport(str.toString(), MODE);
JTextArea textArea = new JTextArea(20,45);
textArea.setText(str.toString());
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JOptionPane.showMessageDialog(rootPane, scrollPane);
}
}