Question: This is my code but need help with the output abstract class BankAccount { protected String accountID; protected double interestRate; protected int balance; public boolean
This is my code but need help with the output
abstract class BankAccount {
protected String accountID; protected double interestRate; protected int balance; public boolean credit(int pennies) { this.balance+=pennies; return true; } public abstract boolean debit(int pennies) ; public int getBalance() { return balance; } public String getAccountID() { return accountID; } public void setAccountID(String accountID) { this.accountID=accountID; } public double getInterestRate() { return interestRate; } public void setInterestRate(double interestRate) { this.interestRate=interestRate; } public abstract void applyInterest() ; public abstract String accountInfo(); }
public class SavingsAccount extends BankAccount {
// No additional fields are required for this class
// Implement the debit method public boolean debit(int pennies) { if (pennies > balance) { return false; } balance -= pennies; return true; }
// Implement the applyInterest method public void applyInterest() { if (balance > 0) { double interestAmount = balance * interestRate; balance += (int) interestAmount; } }
// Implement the accountInfo method public String accountInfo() { return "Type of Account : Savings" + " " + "Account ID : " + accountID + " " + "Current Balance : $" + balance / 100 + "." + balance % 100 + " " + "Interest rate : " + interestRate + "%"; } }
Given a new SavingsAccount (sa), after sa.setAccountID("1111-2222-3333-4444") and sa.credit(1000) and sa.setInterestRate(0.025), accountInfo should return a correctly formatted String
Test feedback
FAIL - expected: ----- Type of Account : Savings Account ID : 1111-2222-3333-4444 Current Balance : $10.00 Interest rate : 2.50% ----- but got: ----- Type of Account : Savings Account ID : 1111-2222-3333-4444 Current Balance : $10.0 Interest rate : 0.025% -----
19:Logic Test 14
0 / 5
Given a new SavingsAccount (sa), after sa.setAccountID("1234-5678-9876-5432") and sa.credit(9876) and sa.setInterestRate(0.123), accountInfo should return a correctly formatted String
Test feedback
FAIL - expected: ----- Type of Account : Savings Account ID : 1234-5678-9876-5432 Current Balance : $98.76 Interest rate : 12.30% ----- but got: ----- Type of Account : Savings Account ID : 1234-5678-9876-5432 Current Balance : $98.76 Interest rate : 0.123% -----
20:Logic Test 15
0 / 5
Given a new SavingsAccount (sa), after sa.setAccountID("1357-2468-0000-9999") and sa.credit(123456) and sa.setInterestRate(0.015), accountInfo should return a correctly formatted String
Test feedback
FAIL - expected: ----- Type of Account : Savings Account ID : 1357-2468-0000-9999 Current Balance : $1234.56 Interest rate : 1.50% ----- but got: ----- Type of Account : Savings Account ID : 1357-2468-0000-9999 Current Balance : $1234.56 Interest rate : 0.015% -----
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
