This repository has been archived by the owner on Oct 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankAccount.java
82 lines (66 loc) · 1.57 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
public class BankAccount {
private String accountNumber;
private double balance;
private String accountHolderName;
private static int numberOfAccounts;
public void deposit(double amount)
{
if (amount < 0)
System.out.println("you can't deposit a negative number");
else
setBalance(getBalance() + amount);
}
public void withdraw(double amount)
{
if (amount > getBalance())
System.out.println("You can't withdraw more than your account.");
else
setBalance(getBalance() - amount);
}
public double getBalance()
{
return balance;
}
public void setAccountHolderName(String accountHolderName)
{
this.accountHolderName = accountHolderName;
}
public String getAccountHolderName()
{
return accountHolderName;
}
public void setAccountNumber(String accountNumber)
{
this.accountNumber = accountNumber;
}
public String getAccountNumber()
{
return accountNumber;
}
public void printReport()
{
System.out.println(getAccountNumber());
System.out.println(getAccountHolderName());
System.out.println(getBalance());
}
public static int getNumberOfAccounts()
{
return numberOfAccounts;
}
BankAccount(String accountNumber, double balance, String accountHolderName)
{
setAccountNumber(accountNumber);
deposit(balance);
setAccountHolderName(accountHolderName);
numberOfAccounts++;
}
BankAccount(String accountNumber, String accountHolderName)
{
this.accountNumber = accountNumber;
this.accountHolderName = accountHolderName;
setBalance(0.0);
}
public void setBalance(double balance) {
this.balance = balance;
}
}