-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathPerson.java
More file actions
32 lines (26 loc) · 814 Bytes
/
Person.java
File metadata and controls
32 lines (26 loc) · 814 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
package com.example.bank;
public class Person {
private String name;
private BankAccount account;
public Person(String name) {
this.name = name;
this.account = new BankAccount(this);
}
public String getName() {
return name;
}
public BankAccount getAccount() {
return account;
}
public void deposit(double amount) {
account.deposit(amount);
System.out.println(name + " deposited " + amount + " to their account.");
}
public void withdraw(double amount) {
if (account.withdraw(amount)) {
System.out.println(name + " withdrew " + amount + " from their account.");
} else {
System.out.println(name + " does not have enough balance to withdraw " + amount + ".");
}
}
}