-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccount.java
More file actions
127 lines (72 loc) · 2.7 KB
/
BankAccount.java
File metadata and controls
127 lines (72 loc) · 2.7 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
import java.util.Date;
import java.util.Scanner;
public class BankAccount {
private float balance;
private long created;
private String bankAccountNumber;
public void setup() {
this.balance = 0;
this.created = new Date().getTime();
String temp = "";
for (int i = 0; i <= 10; ++i) {
String r = "" + (int) (Math.random() * 10);
temp = temp.concat(r);
}
this.bankAccountNumber = temp;
System.out.println("\nWelcome to your BankAccount\n");
System.out.println("\t BankAccount Number: " + this.bankAccountNumber);
}
public void showBalance() {
System.out.printf("\n\t Your balance is: %.2f #", this.balance);
}
public void withdrawAmount(float amount) {
if (amount <= 0) {
System.out.println(
"\n Amount to withdraw must be greater than 0 #");
return;
}
if (amount > this.balance) {
System.out.printf(
"\n You do not have sufficient balance, please make a deposit first. Your current balance is %.2f # \n",
this.balance);
}
else {
this.balance -= amount;
System.out.printf("\n Withdrawal of %.2f # was successful, your new balance is %.2f #\n", amount,
this.balance);
}
}
public void depositAmount(float amount) {
if (amount <= 0) {
System.out.println(
"\n Amount to deposit must be greater than 0 #");
return;
}
this.balance += amount;
System.out.printf("\n Deposit of %.2f # was successful, your new balance is %.2f #\n", amount,
this.balance);
}
public void computeInterest() {
long now = new Date().getTime();
long elpased = now - this.created;
int secs = (int) elpased / 1000;
System.out.printf(
"\n\n\tInterest is: %.2f # in %d seconds at 0.0001 percent per second. \n",
(this.balance * 0.0001) * secs, secs);
}
// Main Function
public static void main(String args[]) {
BankAccount BankAccount = new BankAccount();
BankAccount.setup();
System.out.println("\n $ Enter an amount to deposit: ");
Scanner scanner = new Scanner(System.in);
float amount = scanner.nextFloat();
BankAccount.depositAmount(amount);
System.out.println("\n $ Enter an amount to withdraw: ");
amount = scanner.nextFloat();
BankAccount.withdrawAmount(amount);
BankAccount.showBalance();
BankAccount.computeInterest();
scanner.close();
}
}