Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / Write an abstract base class in Java according to Interface specifications given in UML

Write an abstract base class in Java according to Interface specifications given in UML

Computer Science

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

Problem Description and Given Info

You must write a public abstract class named BankAccount with fields and methods as defined below.

 


UML CLass Diagram: BankAccount

 

Structure of the Fields

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

  • a protected field named accountID of type String, initialized to "0000-0000-0000-0000"
  • a protected field named interestRate of type double, initialized to 0.0
  • a protected field named balance of type int, initialized to 0

Structure of the Methods

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

  • a public method named credit that takes an int argument and returns a boolean
  • a public abstract method named debit that takes an int argument and returns a boolean
  • a public method named getBalance that takes no arguments and returns an int
  • a public method named getAccountID that takes no arguments and returns an String
  • a public method named setAccountID that takes a String argument and returns nothing
  • a public method named getInterestRate that takes no arguments and returns a double
  • a public method named setInterestRate that takes a double argument and returns nothing
  • a public abstract method named applyInterest that takes no arguments and returns nothing
  • a public abstract method named accountInfo that takes no arguments and returns a String

Behavior of the Methods

  • The credit method should add the argument amount to the balance
  • The debit method is abstract so there will be no behavior or method body
  • The getBalance method should return the balance
  • The getAccountID method should return the accountID
  • The setAccountID method should store the argument value in the accountID field
  • The getBalance method should return the balance
  • The getInterestRate method should return the interestRate
  • The setInterestRate method should store the argument amount in the interestRate field
  • The applyInterest method is abstract so there will be no behavior or method body
  • The accountInfo method is abstract so there will be no behavior or method body

Additional Information

  • Since this is an abstract class, you will not be able to instantiate any object from it.
  • You are given a TestAccount class that inherits\extends the BankAccount class. you may use this to help with testing your BankAccount class.
  • You are also given a Main class with a main method where you can write code to test your BankAccount class.

All Bank Accounts

  1. All accounts have balance, credit and debit amounts, and fees stored and passed as a number of pennies (int).
  2. All debit amounts will be subtracted from the balance, and all credit amounts will be added to the balance.
  3. All bank accounts have a non-negative interest rate (0.02 would be a 2% interest rate).
  4. The credit method will always return true.

 

  1. 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

  1. All accounts have balance, credit and debit amounts, and fees stored and passed as a number of pennies (int).
  2. All debit amounts will be subtracted from the balance, and all credit amounts will be added to the balance.
  3. All bank accounts have a non-negative interest rate (0.02 would be a 2% interest rate).
  4. When applying interest, interest amount is calculated by multiplying the balance by the interest rate.
  5. When applying interest, interest amount is always added to the balance, and any fractional part will be rounded down.
  6. Interest will not be applied to any Savings or Checking account with a balance of zero or less.
  7. Debit methods will return false if the transaction cannot be made because of insufficient balance or insufficient credit limit. Otherwise they will return true.
  8. The credit method will always return true.

Savings Accounts

  1. A SavingsAccount cannot have a negative balance.
    • The debit method will return false if an attempt to overdraw the account is made.

 

 

  1. 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 CheckingAccount with fields and methods as defined below, and that inherits from (extends) the BankAccount class.

 


UML CLass Diagram: CheckingAccount Inherits BankAccount

 

Structure of the Fields

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

  • a private field named overdraftFee of type int initialized to 0

Structure of the Methods

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

  • a public method named debit that takes an int argument and returns a boolean
  • a public method named setFee that takes an int and returns nothing
  • a public method named getFee 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 CheckingAccount concrete derived class.

Behavior of the Methods

  • The debit method should subtract the argument amount from the balance. The debit method should always return true.
  • The setFee method should store the argument amount in the overdraftFee field.
  • The getFee method should return the value stored in the overdraftFee field.
  • 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 : Checking

Account ID      : 1111-2222-3333-4444

Current Balance : $123.45

Interest rate   : 1.50%

Overdraft Fee   : $20.00

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

  1. All accounts have balance, credit and debit amounts, and fees stored and passed as a number of pennies (int).
  2. All debit amounts will be subtracted from the balance, and all credit amounts will be added to the balance.
  3. All bank accounts have a non-negative interest rate (0.02 would be a 2% interest rate).
  4. When applying interest, interest amount is calculated by multiplying the balance by the interest rate.
  5. When applying interest, interest amount is always added to the balance, and any fractional part will be rounded down.
  6. Interest will not be applied to any Savings or Checking account with a balance of zero or less.
  7. Debit methods will return false if the transaction cannot be made because of insufficient balance or insufficient credit limit. Otherwise they will return true.
  8. The credit method will always return true.

Checking Accounts

  1. A CheckingAccount can have a negative balance.
    • The debit method for the CheckingAccount will always return true.
  2. Any CheckingAccount debit that ends with a negative balance will incur an overdraftFee (i.e. the overdraftFee amount will be subtracted from the balance). A CheckingAccount debit will always succeed.
  3. Interest will not be applied to a CheckingAccountwith a negative balance.

 

 

  1. 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 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

  1. All accounts have balance, credit and debit amounts, fees, and limits stored and passed as a number of pennies (int).
  2. All debit amounts will be subtracted from the balance, and all credit amounts will be added to the balance.
  3. All bank accounts have a non-negative interest rate (0.02 would be a 2% interest rate).
  4. When applying interest, interest amount is calculated by multiplying the balance by the interest rate.
  5. When applying interest, interest amount is always added to the balance, and any fractional part will be rounded down.
  6. Interest will not be applied to any Savings or Checking account with a balance of zero or less.
  7. Debit methods will return false if the transaction cannot be made because of insufficient balance or insufficient credit limit. Otherwise they will return true.
  8. The credit method will always return true.

Creditcard Accounts

  1. 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.
  2. 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.
  3. Interest will not be applied to a CreditcardAccount with a positive or zero balance.

 

 

 

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions