Repository navigation
Expand file tree
/
Copy pathAccount.java
More file actions
76 lines (57 loc) · 1.85 KB
/
Copy pathAccount.java
File metadata and controls
76 lines (57 loc) · 1.85 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
package bankmanagement;
public class Account {
private double balance = 0;
private double interest = 0.2;
private int accountNum;
private static int numOfAccounts = 1;
Account(){
accountNum = numOfAccounts++;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public double getInterest() {
return interest * 100;
}
public void setInterest(double interest) {
this.interest = interest;
}
public int getAccountNum() {
return accountNum;
}
public void withdraw(double amount){
if(amount + 5 > balance){
System.out.println("You don't have enough funds!");
System.out.println("Please try again.\n");
return;
}
balance = balance - amount + 5;
checkInterest(0);
System.out.println("You have withdrawn $" + amount + " and incurred a fee of $5");
System.out.println("Your current balance is $" + balance);
}
public void deposit(double amount){
if(amount <= 0){
System.out.println("You cannot deposit negative values");
return;
}
checkInterest(amount);
amount = amount + amount * interest;
balance = balance + amount;
System.out.println("You have deposited $" + amount + " with an interest rate of " + (interest * 100) + "%");
System.out.println("Your current balance is $" + balance);
}
public void checkInterest(double amount) {
if(balance + amount> 10000){
interest = 0.05;
}else{
interest = 0.02;
}
}
public String toData(){
return "";
}
}