-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvestor.java
More file actions
333 lines (216 loc) · 8.75 KB
/
Copy pathInvestor.java
File metadata and controls
333 lines (216 loc) · 8.75 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.EventQueue;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Investor {
static class Inv{
double initialInvestment;
double percentage;
double individualEarnings;
static double totalEarningsPer;
static double totalEarnings;
static double totalInvestment;
Inv(double initial){
this.initialInvestment = initial;
}
public static void setTotalInvestment(double total) {
totalInvestment = total;
}
public static double getTotalInvestment() {
return totalInvestment;
}
public void setPercentage(double initialInvestment) {
this.percentage = (initialInvestment/totalInvestment) * 100;
this.percentage = (double) Math.round(this.percentage * (double) 100) / (double) 100;
}
public double getPercentage() {
return this.percentage;
}
public static void setTotalEarningsPer(double currentInvestment) {
totalEarningsPer = ((currentInvestment/getTotalInvestment()) -1) * 100;
totalEarningsPer = (double) Math.round(totalEarningsPer * (double) 100) / (double) 100;
}
public static double getTotalEarningsPer() {
return totalEarningsPer;
}
public static void totalEarnings(double currentInvestment) {
totalEarnings = currentInvestment - totalInvestment;
totalEarnings = (double) Math.round(totalEarnings * (double) 100) / (double) 100;
}
public void setIndividualEarnings(Inv name) {
name.individualEarnings = totalEarnings * (name.getPercentage()/100);
name.individualEarnings = (double) Math.round(name.individualEarnings * (double) 100) / (double) 100;
}
public double getIndividualEarnings() {
return individualEarnings;
}
}
private JFrame frame;
private JTextField tfAdd;
private JTextField textField_2;
private JTextField tfAbdallahInvest;
private JTextField tfAbdallahPer;
private JTextField tfAndresPer;
private JTextField tfAbdallahEarnings;
private JTextField tfAndresEarnings;
private JTextField tfAndresInvest;
private JTextField tfTotalInvestment;
private JTextField tfTotalEarnings;
private JTextField tfTotalEarningPer;
private JTextField tfCurrentInvest;
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Investor window = new Investor();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public Investor() {
initialize();
}
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 450, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.getContentPane().setLayout(null);
JLabel lblDate = new JLabel("");
lblDate.setBounds(226, 71, 132, 16);
frame.getContentPane().add(lblDate);
//////////////////////////////////////////
Inv Abdallah = new Inv(6215);
Inv Andres = new Inv(1756);
lblDate.setText("As of 03/13/2019");
//////////////////////////////////////////
JLabel lblAdd = new JLabel("Add ");
lblAdd.setBounds(6, 11, 29, 16);
frame.getContentPane().add(lblAdd);
JLabel lblAbdallah_1 = new JLabel("Abdallah:");
lblAbdallah_1.setBounds(6,211,65,20);
frame.getContentPane().add(lblAbdallah_1);
JButton btnGetData = new JButton("Get data");
btnGetData.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Total Initial Investment
double total = Abdallah.initialInvestment + Andres.initialInvestment;
Inv.setTotalInvestment(total);
tfTotalInvestment.setText(Double.toString(Inv.getTotalInvestment()));
//Individual Investments and Percentages
tfAndresInvest.setText(Double.toString(Andres.initialInvestment));
tfAbdallahInvest.setText(Double.toString(Abdallah.initialInvestment));
Andres.setPercentage(Andres.initialInvestment);
Abdallah.setPercentage(Abdallah.initialInvestment);
tfAndresPer.setText(Double.toString(Andres.getPercentage()));
System.out.println(Andres.getPercentage());
tfAbdallahPer.setText(Double.toString(Abdallah.getPercentage()));
System.out.println(Abdallah.getPercentage());
//Total Earnings
Inv.setTotalEarningsPer(Double.parseDouble(tfCurrentInvest.getText()));
tfTotalEarningPer.setText(Double.toString(Inv.getTotalEarningsPer()));
Inv.totalEarnings(Double.parseDouble(tfCurrentInvest.getText()));
tfTotalEarnings.setText(Double.toString(Inv.totalEarnings));
// Individual Earnings
Andres.setIndividualEarnings(Andres);
tfAndresEarnings.setText(Double.toString(Andres.getIndividualEarnings()));
Abdallah.setIndividualEarnings(Abdallah);
tfAbdallahEarnings.setText(Double.toString(Abdallah.getIndividualEarnings()));
}
});
btnGetData.setBounds(329,199,106,66);
frame.getContentPane().add(btnGetData);
tfAdd = new JTextField();
tfAdd.setBounds(41,9,132,20);
frame.getContentPane().add(tfAdd);
JLabel lblInitialInvestment = new JLabel("Investment");
frame.getContentPane().add(lblInitialInvestment);
JLabel lblTo = new JLabel("$ to");
lblTo.setBounds(185, 11, 29, 16);
frame.getContentPane().add(lblTo);
textField_2 = new JTextField();
textField_2.setBounds(50,50,50,50);
JLabel lblEarnings = new JLabel("Investment");
frame.getContentPane().add(lblEarnings);
lblEarnings.setBounds(78,182,75,26);
tfAbdallahInvest = new JTextField();
tfAbdallahInvest.setBounds(76,212,75,18);
frame.getContentPane().add(tfAbdallahInvest);
JLabel label = new JLabel("%");
frame.getContentPane().add(label);
label.setBounds(170,185,9,20);
JLabel lblAndres = new JLabel("Andres:");
frame.getContentPane().add(lblAndres);
lblAndres.setBounds(6,243,58,22);
tfAbdallahPer = new JTextField();
tfAbdallahPer.setBounds(150, 212, 50, 18);
frame.getContentPane().add(tfAbdallahPer);
tfAndresPer = new JTextField();
tfAndresPer.setBounds(150, 243, 50, 18);
frame.getContentPane().add(tfAndresPer);
JLabel lblEarnings_1 = new JLabel("Earnings");
lblEarnings_1.setBounds(245, 182, 58, 26);
frame.getContentPane().add(lblEarnings_1);
tfAbdallahEarnings = new JTextField();
tfAbdallahEarnings.setBounds(237, 212, 75, 18);
frame.getContentPane().add(tfAbdallahEarnings);
tfAndresEarnings = new JTextField();
tfAndresEarnings.setBounds(237, 245, 75, 18);
frame.getContentPane().add(tfAndresEarnings);
tfAndresInvest = new JTextField();
tfAndresInvest.setBounds(76, 243, 75, 18);
frame.getContentPane().add(tfAndresInvest);
JLabel lblTotalInvestment = new JLabel("Initial Investment");
lblTotalInvestment.setBounds(6, 71, 121, 16);
frame.getContentPane().add(lblTotalInvestment);
tfTotalInvestment = new JTextField();
tfTotalInvestment.setBounds(127, 69, 87, 20);
frame.getContentPane().add(tfTotalInvestment);
JLabel lblTotalEarnings = new JLabel("Total Earnings");
lblTotalEarnings.setBounds(229, 121, 106, 16);
frame.getContentPane().add(lblTotalEarnings);
tfTotalEarnings = new JTextField();
tfTotalEarnings.setBounds(338, 119, 97, 20);
frame.getContentPane().add(tfTotalEarnings);
JLabel lblTotalEarningsPer = new JLabel("Total Earnings %");
lblTotalEarningsPer.setBounds(229, 152, 106, 16);
frame.getContentPane().add(lblTotalEarningsPer);
tfTotalEarningPer = new JTextField();
tfTotalEarningPer.setBounds(338, 150, 97, 20);
frame.getContentPane().add(tfTotalEarningPer);
JButton btnAbdallah = new JButton("Abdallah");
btnAbdallah.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String a = tfAdd.getText();
if (!"".equals(a)) {
Abdallah.initialInvestment += Double.parseDouble(tfAdd.getText());
}
}
});
btnAbdallah.setBounds(218, 6, 117, 29);
frame.getContentPane().add(btnAbdallah);
JButton btnAndres = new JButton("Andres");
btnAndres.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String a = tfAdd.getText();
if (!"".equals(a)) {
Andres.initialInvestment += Double.parseDouble(tfAdd.getText());
}
}
});
btnAndres.setBounds(326, 6, 117, 29);
frame.getContentPane().add(btnAndres);
JLabel lblCurrentInvestment = new JLabel("Current Investment");
lblCurrentInvestment.setBounds(41, 121, 132, 16);
frame.getContentPane().add(lblCurrentInvestment);
tfCurrentInvest = new JTextField();
tfCurrentInvest.setBounds(51, 137, 102, 20);
frame.getContentPane().add(tfCurrentInvest);
}
}