lasacs.com/ask/506
ASK
lasacs.com/ask/505
ASK
How many non-constructor methods can be invoked by a SavingsAccount object?
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
Q1
ASK
Which correctly implements the default constructor of the SavingsAccount class?
I interestRate = 0;� super();�II super();� interestRate = 0;�III super();
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
c
Q2
ASK
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
interestRate = rate;
interestRate = rate;
interestRate = rate;
interestRate = rate;
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
Which is the correct implementation of the initialization constructor in the SavingsAcccount class?
Q3
ASK
Which implements the CheckingAccount constructor correctly?
I super(acctBalance); �II super();� deposit(acctBalance);�III deposit(acctBalance);
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
Q4
ASK
Correct withdraw() implementation in CheckingAccount?
A. super.withdraw(amount); D. withdraw(amount);� if (balance < MIN_BALANCE) if (getBalance() < MIN_BALANCE)� super.withdraw(FEE); withdraw(FEE);�B. withdraw(amount); E. balance -= amount;� if (balance < MIN_BALANCE) if (balance < MIN_BALANCE)� withdraw(FEE) balance -= FEE;�C. super.withdraw(amount);� if (getBalance() < MIN_BALANCE)� super.withdraw(FEE);
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
Q5
ASK
Redefining the withdraw() method in the CheckingAccount class is an example of
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
Q6
ASK
Which will cause an error?
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends BankAccount {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
BankAccount b = new BankAccount(1400);�BankAccount s = new SavingsAccount(1000,0.04);�BankAccount c = new CheckingAccount(500);
Q7
ASK
To test polymorphism you must use this method
class BankAccount {� private double balance;� public BankAccount()
{ balance = 0; }� public BankAccount(double acctBalance) � { balance = acctBalance; }� public void deposit(double amount) � { balance += amount; }� public void withdraw(double amount)� { balance -= amount; }� public double getBalance() {� { return balance; }�}�
public class SavingsAccount extends Bank Account {� private double interestRate;� public SavingsAccount() {� { /* implementation not shown */ } � public SavingsAccount(double acctBalance, double rate)
{ /* implementation not shown */ }
public void addInterest() //Add interest to balance� { /* implementation not shown */ }�}�
public class CheckingAccount extends BankAccount {� private static final double FEE = 2.0;� private static final double MIN_BALANCE = 50.0;� public CheckingAccount(double acctBalance)� { /* implementation not shown */ } � /* FEE of $2 deducted if withdrawal leaves balance less � * than MIN_BALANCE. Allows for negative balance. */� public void withdraw(double amount) � { /* implementation not shown */ } �}
BankAccount b = new BankAccount(1400);�BankAccount s = new SavingsAccount(1000,0.04);�BankAccount c = new CheckingAccount(500);
ASK