This repository has been archived by the owner on Dec 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankAccount.java
94 lines (80 loc) · 1.61 KB
/
BankAccount.java
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
/**
* A bank account has a balance that can be changed by deposits and withdrawals.
*/
public class BankAccount {
// instance fields
private double balance;
String ownerName;
double rate;
static int AccNo;
/**
* Constructs a bank account with a zero balance.
*/
public BankAccount() {
balance = 0;
ownerName = null;
rate = 0;
AccNo = 0;
}
/**
* Constructs a bank account for the user with a given balance.
*/
public BankAccount(String name, double initialBalance, double interest, int acc) {
balance = initialBalance;
ownerName = name;
rate = interest;
AccNo = acc;
}
/**
* Deposits money into the bank account.
*
* @param amount
* the amount to deposit
*/
public void deposit(double amount) {
if (amount > 0)
balance = balance + amount;
}
/**
* Withdraws money from the bank account.
*
* @param amount
* the amount to withdraw
*/
public void withdraw(double amount) {
if (balance >= amount)
balance = balance - amount;
}
public void addRate(double interest){
if (interest>0)
rate = interest;
}
public void addAcc(int acc){
if (acc>0)
AccNo = acc;
}
public void addOwner(String own){
ownerName = own;
}
public int getAccNo(){
return AccNo;
}
public String owner(){
return ownerName;
}
public double getRate(){
return rate;
}
/**
* Gets the current balance of the bank account.
*
* @return the current balance
*/
public double getBalance() {
return balance;
}
public double getEndofMonthBalance(){
double endofMonthBalance = balance + (balance*rate);
return endofMonthBalance;
}
}