Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write an derived class in Java according to Interface specifications given in UML. Implement base class Interfaces in java according to specifications given in UML.

Write an derived class in Java according to Interface specifications given in UML.

Implement base class Interfaces in java according to specifications given in UML.

Problem Description and Given Info

You must write a public class named SavngsAccount with fields and methods as defined below, and that inherits from (extends) the BankAccount class.

UML CLass Diagram: SavingsAccount Inherits BankAccount

Structure of the Fields

As described by the UML Class Diagram above, your SavingsAccount class must have the following fields:

The SavingsAccount class has no required fields.

Structure of the Methods

As described by the UML Class Diagram above, your SavingsAccount class must have the following methods:

a public method named debit that takes an int argument and returns a boolean

a public method named applyInterest that takes no arguments and returns nothing

a public method named accountInfo that takes no arguments and returns a String

Note that these three methods are defined as abstract in the BankAccount base class. You will be overriding and implementing these methods in this SavingsAccount concrete derived class.

Behavior of the Methods

The debit method should subtract the argument amount from the balance, but only if the amount is not more than the balance. This method should return true if the amount was subtracted from the balance, otherwise it should return false.

The applyInterest method should compute the interest amount and add this amount to the balance, but only if the balance is greater than 0.

The accountInfo method will return a string formatted exactly like this:

Type of Account : Savings Account ID : 1111-2222-3333-4444 Current Balance : $123.45 Interest rate : 1.50% 

Additional Information

BankAccount Class

Copy and paste your BankAccount class code from your Bank Account (Individual Assignment) into the BankAccount.Java file in the editor below.

All Bank Accounts

All accounts have balance, credit and debit amounts, and fees stored and passed as a number of pennies (int).

All debit amounts will be subtracted from the balance, and all credit amounts will be added to the balance.

All bank accounts have a non-negative interest rate (0.02 would be a 2% interest rate).

When applying interest, interest amount is calculated by multiplying the balance by the interest rate.

When applying interest, interest amount is always added to the balance, and any fractional part will be rounded down.

Interest will not be applied to any Savings or Checking account with a balance of zero or less.

Debit methods will return false if the transaction cannot be made because of insufficient balance or insufficient credit limit. Otherwise they will return true.

The credit method will always return true.

Savings Accounts

A SavingsAccount cannot have a negative balance.

The debit method will return false if an attempt to overdraw the account is made.

This is what I Got so far with the

public 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 abstract class SavingsAccount { 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 balance() { 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 CreditCardAccount extends BankAccount{ private int limit; public boolean debit(int pennies) { if( (this.balance-pennies)<=limit) { this.balance-=pennies; return true; } return false; } public int getlimit() { return limit; } public void setlimit(int creditLimit) { this.limit=creditLimit; } public void applyInterest() { if(this.balance<0) { double interest=(interestRate/100)*balance; this.balance+=interest; } } public String accountInfo() { return "Type of Account : CreditCard "+"Account ID : "+accountID+" Current Balance : $"+balance+" Interest rate : "+interestRate+"% "+"Credit Limit : $"+limit; } }

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

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

The company has fair promotion/advancement policies.

Answered: 1 week ago