Respuesta :
Answer:
C++ code is explained below
Explanation:
class Account {
double balance;
double add(double sum) {
balance += sum;
return sum;
}
double withdraw(double sum) {
if (sum > balance) {
balance -= 5;
return -5; // this will come in handy in Prob. 6
} else {
balance -= sum;
return balance; // Notice: always >= 0 (never < 0)
}
}
double inquire() { return balance; }
Account() { balance = 0; }
Account(double sum) { balance = sum; }
double interest (double rate) {
return rate * balance;
}
}
_______________________________
class Bank {
Account checking;
Account savings;
void deposit(double amount, String account) {
if (account.equals("C")) checking.add(amount);
else // my default
savings.add(amount);
}
void withdraw(double amount, String account) {
if (account.equals("C")) checking.withdraw(amount);
else // my default
savings.withdraw(amount);
}
void transfer (double amount, String account) {
if (account.equals("C"))
if (checking.withdraw(amount) >= 0)
savings.add(amount);
else checking.add(5); // somewhat fault-tolerant
else // default
if (savings.withdraw(amount) >= 0)
checking.add(amount);
else savings.add(5); // no penalty for transfers
}
void printBalances() {
System.out.println(
"Checking: " + checking.inquire() +
"\nSavings: " + savings.inquire()
);
}
}