Understand how to model real concepts using classes, fields, constructors, and methods.
BankAccountpublic class BankAccount {
private final String id;
private long balanceCents;
public BankAccount(String id) {
this.id = id;
this.balanceCents = 0;
}
public void deposit(long cents) {
if (cents <= 0) throw new IllegalArgumentException("cents must be positive");
balanceCents += cents;
}
public void withdraw(long cents) {
if (cents <= 0) throw new IllegalArgumentException("cents must be positive");
if (cents > balanceCents) throw new IllegalStateException("insufficient funds");
balanceCents -= cents;
}
public long getBalanceCents() {
return balanceCents;
}
public String getId() {
return id;
}
}
private.transferTo(BankAccount other, long cents) method.id.toString() that prints id and balance.