Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

UML CLass Diagram: CreditcardAccount Inherits BankAccount

Structure of the Fields

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

a private field named limit of type int initialized to 0

Structure of the Methods

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

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

a public method named setLimit that takes an int and returns nothing

a public method named getLimit that takes no arguments and returns an int

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 three of these methods are defined as abstract in the BankAccount base class. You will be overriding and implementing these methods in this CreditcardAccount concrete derived class.

Behavior of the Methods

The debit method should subtract the argument amount from the balance, but only if the amount would not cause the current balance to violate the credit limit. This method should return true if the amount was subtracted from the balance, otherwise it should return false.

The setLimit method should store the argument amount in the limit field.

The getLimit method should return the value stored in the limit field.

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

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

Type of Account : Creditcard Account ID : 1111-2222-3333-4444 Current Balance : $123.45 Interest rate : 1.50% Credit Limit : $10000.00 

Note that, while the current balance of a CreditcardAccount will almost always be negative, it should be shown as a positive value in the String returned by the accoutnInfo method.

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, fees, and limits 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.

Creditcard Accounts

The balance of a CreditcardAccount cannot overrun its credit limit.

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

The balance of a CreditcardAccount will generally be negative, because when you spend money on a credit card, you are borrowing money, and the negative balance reflects money that you owe.

The credit limit will be stored as a positive value. For example, a credit limit of $10000.00 will be stored in the limit field as the int value 1000000.

Interest will not be applied to a CreditcardAccount with a positive or zero balance.

_____________________________________________________________

CreditcardAccount code:

public class CreditcardAccount extends BankAccount { private int limit = 0; public boolean debit(int pennies) { if (balance > limit) { super.balance -= pennies; return true; } return false; }

public int getLimit() { return limit; } public void setLimit(int limit) { if (limit >= 0) { this.limit = limit; } }

public void applyInterest() { if (balance

public String accountInfo() { String result = String.format("%-20s:%s ", "Type of Account", "Creditcard"); result += String.format("%-20s:%s ", "Account ID", accountID); result += String.format("%-20s:$%.2f ", "Current Balance", (double) balance); result += String.format("%-20s:%.2f%% ", "Interest Rate", interestRate); result += String.format("%-20s:$%.2f ", "Credit limit", (double) limit); return result; } }

BankAccount code:

public abstract class BankAccount { protected String accountID; protected double interestRate; protected int balance; public BankAccount() { accountID = "0000-0000-0000-0000"; interestRate = 0.0; balance = 0; } public boolean credit(int pennies) { balance += pennies; return true; } public abstract boolean debit(int pennies); public double 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(); }

image text in transcribedimage text in transcribed

image text in transcribed

Can anyone fix the problem that showing in pic! I have to get interest rate correct to get the points

15:Logic Test 08 0/4 Given a new CreditcardAccount (ca), after ca.setLimit(1000000), ca.debit(1000000), should return true Test feedback 17:Logic Test 10 Given a CreditcardAccount (ca), with balance of 0, after ca.setLimit(1500000) and ca.debit(3000), getBalance should return 3000 Compilation failed 18:Logic Test 11 0/4 Given a CreditcardAccount (ca), with balance of 0, after ca.setLimit(1500000) and ca.debit(1500000), getBalance should return 1500000 Compilation failed Given a CreditcardAccount (ca), with balance of 0, after ca.setLimit(1000000) and ca.debit(1500000), getBalance should return 0 Compilation failed 20:Logic Test 13 0/4 Given a new CreditcardAccount (ca), ca.setLimit(1000000) and ca.setInterestRate(0.10) and ca.debit(1000) and ca.applylnterest () , getBalance should return 1100 Compilation failed \begin{tabular}{c|c} zyLabsunitTest.java: 13: error: incompatible types: possible lossy conv \\ int actual = obj.getialance (); \end{tabular} 21:Logic Test 14 0/4 Given a new CreditcardAccount (ca), ca.setLimit(1000000) and ca.setInterestRate(0.025) and ca.debit(2500) and ca.applylnterest () , getBalance should return 2562 Compilation failed Given a new CreditcardAccount (ca), after ca.setLimit(2000000) and ca.setAccountID("1111-2222-3333-4444") and ca.debit(1000) and ca.setInterestRate(0.025), 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

How easy the information is to remember

Answered: 1 week ago

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago