Question
Consider theBankAccountclass below. public class BankAccount { private final String ACCOUNT_NUMBER; private double balance; public BankAccount(String acctNumber, double beginningBalance) { ACCOUNT_NUMBER = acctNumber; balance =
Consider theBankAccountclass below.
public class BankAccount
{
private final String ACCOUNT_NUMBER;
private double balance;
public BankAccount(String acctNumber, double beginningBalance)
{
ACCOUNT_NUMBER = acctNumber;
balance = beginningBalance;
}
public boolean withdraw(double withdrawAmount)
{
/*missing code*/
}
}
The class contains thewithdrawmethod, which is intended to update the instance variablebalanceunder certain conditions and return a value indicating whether the withdrawal was successful. If subtractingwithdrawAmountfrombalancewould lead to a negative balance,balanceis unchanged and the withdrawal is considered unsuccessful. Otherwise,balanceis decreased bywithdrawAmountand the withdrawal is considered successful.
Which of the following code segments can replace/*missing code*/to ensure that thewithdrawmethod works as intended?
I.
if (withdrawAmount > balance)
{
return "Overdraft";
}
else
{
balance -= withdrawAmount;
return true;
}
II.
if (withdrawAmount > balance)
{
return false;
}
else
{
balance -= withdrawAmount;
return balance;
}
III.
if (withdrawAmount > balance)
{
return false;
}
else
{
balance -= withdrawAmount;
return true;
}
- A
- I only
- B
- II only
- C
- III only
- D
- I and II only
- E
- I, II, and III
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started