Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

abstract class BankAccount { //protected field named accountID of type String, initialized to 0000-0000-0000-0000 protected String accountID = 0000-0000-0000-0000; //protected field named interestRate of type

abstract class BankAccount { //protected field named accountID of type String, initialized to "0000-0000-0000-0000" protected String accountID = "0000-0000-0000-0000"; //protected field named interestRate of type double, initialized to 0.0 protected double interestRate = 0; //protected field named currentBalance of type int, initialized to 0 protected int balance = 0; //public method named credit that takes an int argument and returns a boolean public boolean credit(int pennies) { balance = balance + pennies; return true; } //public abstract method named debit that takes an int argument and returns a boolean public abstract boolean debit(int pennies); //public method named getBalance that takes no arguments and returns an int public int getBalance() { return balance; } //public method named getAccountID that takes no arguments and returns an String public String getAccountID() { return accountID; } //public method named setAccountID that takes a String argument and returns nothing public void setAccountID(String accountID) { this.accountID = accountID; } //public method named getInterestRate that takes no arguments and returns a double public double getInterestRate() { return interestRate; } //public method named setInterestRate that takes a double argument and returns nothing public void setInterestRate(double interestRate) { this.interestRate = interestRate; } //public abstract method named applyInterest that takes no arguments and returns nothing public abstract void applyInterest(); //public abstract method named accountInfo that takes no arguments and returns a String 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 + "%"; } }

Cant figure out bottom output

image text in transcribedimage text in transcribed

vingsAccount (sa), after sa.setAccountID("1234-5678-9876-5432") and s ate(0.123), accountinfo should return a correctly formatted String FAIL - expected: Type of Account : Savings Account ID : 1234567898765432 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 Given a new SavingsAccount (sa), after sa.setAccountID("1357-2468-0000-9999") and sa.credit( sa.setInterestRate(0.015), accountInfo should return a correctly formatted String Test feedback

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Write a short note on rancidity and corrosiveness.

Answered: 1 week ago