Java Reference
In-Depth Information
}
if (temp.compareTo(this.getAmount()) < 0) {
return true;
}
return false;
}
 
@Override
public void withdraw(String withdrawal) throws IllegalWithdrawal {
if (isValidWithdrawal(withdrawal)) {
this.setAmount(this.getAmount()
.subtract(new BigDecimal(withdrawal)));
} else {
throw new IllegalWithdrawal();
}
}
 
public String getName() {
return name;
}
 
private void setName(String name) {
this.name = name;
}
 
public BigDecimal getAmount() {
return amount;
}
 
private void setAmount(BigDecimal amount) {
this.amount = amount;
}
 
@Override
public String toString() {
return "SavingsAccount " + this.getName()
+ ": Balance = " + this.getAmount();
}
}
7.
Create another new class called CheckingAccount . Structure it similarly to the SavingsAccount
class. This time add a minBalance static variable to maintain a minimum balance of 100 dollars in
all checking accounts. Override the toString() method to print information about your accounts.
Your CheckingAccount class may look like this:
import java.math.BigDecimal;
 
public class CheckingAccount implements Accountable {
private String name;
private BigDecimal amount = new BigDecimal("0.00");
private static BigDecimal minBalance = new BigDecimal("100.00");
 
public CheckingAccount(String name, String amount) throws IllegalAccount {
if (isValidDeposit(amount)) {
Search WWH ::




Custom Search