-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCheckingAccount.java
More file actions
36 lines (30 loc) · 870 Bytes
/
CheckingAccount.java
File metadata and controls
36 lines (30 loc) · 870 Bytes
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
public class CheckingAccount{
private double myBalance;
private int myAccountNumber;
public CheckingAccount(){
myBalance = 0.0;
myAccountNumber = 0;
}
public CheckingAccount(double initialBalance, int acctNum){
myBalance = initialBalance;
myAccountNumber = acctNum;
}
public double getBalance(){
if(myBalance < 0){
throw new IllegalArgumentException("Balance less than 0");
}else
return myBalance;
}
public void deposit(double amount){
if(amount < 0){
throw new IllegalArgumentException("Cannot deposit less than 0");
}else
myBalance += amount;
}
public void withdraw( double amount ){
if(amount > myBalance){
throw new IllegalArgumentException("Cannot withdraw more than your current balance");
}else
myBalance -= amount;
}
}