-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBankAccount.java
More file actions
41 lines (34 loc) · 1.05 KB
/
Copy pathBankAccount.java
File metadata and controls
41 lines (34 loc) · 1.05 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
public class BankAccount {
private String owner;
private int balance;
public BankAccount(String owner) {
this(owner, 0);
}//end ctor
public BankAccount(String owner, int balance) {
this.owner = owner;
this.balance = balance;
}//end ctor
public void deposit(int amount) {
if(amount > 0) {
balance += amount; //balance = balance + amount;
}
else {
System.out.println("Amount to deposit must be greater than 0");
}//end if-else
}//end deposit
public void withdraw(int amount) {
if(amount > 0 && amount <= balance) {
balance -= amount; //balance = balance - amount;
}
else {
System.out.println("The amount to deposit must be greater than 0 " +
"and less than your balance.");
}
}//end withdraw
public String getOwner() {
return owner;
}
public int getBalance() {
return balance;
}
}//end BankAccount