Question

Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you w

Class Account is the base class and will offer the state and behavior common to all the derived classes. Class Account must,

Copy constructor: Constructs a new account with its balance and account number the same as that of the input parameter acct.

o SavingAccount (double bal) Second Constructor: Uses the first constructor to set the balance to bal and the rate to the def

o CheckingAccount(double bal, double limit, double charge) First Constructor: Creates a new checking account and uses the bas

code must be in java.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODE IN JAVA:

Account.java file:

public class Account {

private static int nextAvailableAcctNumber = 0 ;

double bal ;

int number ;

public Account(double bal) {

this.bal = bal ;

this.number = nextAvailableAcctNumber ;

nextAvailableAcctNumber += 1 ;

}

public Account() {

this.bal = 0 ;

this.number = nextAvailableAcctNumber ;

nextAvailableAcctNumber += 1 ;

}

public Account(Account acct) {

this.bal = acct.bal ;

this.number = acct.number ;

}

void deposit(double amt) {

if(amt > 0)

bal += amt ;

}

public String toString() {

return "Account Number:"+number+" and Balance:"+bal;

}

boolean equals(Account thisAccount) {

if(this.number == thisAccount.number)

return true;

return false;

}

double getBal() {

return bal ;

}

int getAcctNumber() {

return number;

}

}

SavingAccount.java file:

public class SavingAccount extends Account{

private double rate ;

private static final double DEFAULT_RATE = 0.05;

private static final double DEFAULT_BAL = 1000.00;

public SavingAccount(double bal, double rate) {

super(bal);

this.rate = rate ;

}

public SavingAccount(double bal) {

super(bal);

this.rate = DEFAULT_RATE;

}

public SavingAccount() {

this(DEFAULT_BAL,DEFAULT_RATE);

}

public SavingAccount(SavingAccount acct) {

super(acct);

this.rate = acct.rate ;

}

double compound() {

double interest = this.bal * this.rate ;

this.bal += interest ;

return interest ;

}

double withd(double amt) {

if(amt <= bal) {

bal -= amt;

return amt ;

}

return 0 ;

}

public String toString() {

return super.toString() + "InterestRate :" + rate ;

}

double getRate() {

return rate ;

}

}

CheckingAccount.java file:

public class CheckingAccount extends Account{

double limit ;

double charge ;

private static final double DEFAULT_LIMIT = 1000.00;

private static final double DEFAULT_CHARGE = 2.00;

public CheckingAccount(double bal, double limit, double charge) {

super(bal);

this.limit = limit ;

this.charge = charge ;

}

public CheckingAccount(double bal) {

this(bal, DEFAULT_LIMIT, DEFAULT_CHARGE);

}

public CheckingAccount() {

this(DEFAULT_LIMIT,DEFAULT_LIMIT,DEFAULT_CHARGE);

}

public CheckingAccount(CheckingAccount acct) {

super(acct);

this.limit = acct.limit ;

this.charge = acct.charge ;

}

double withd(double amt) {

if(amt <= bal) {

bal -= amt;

if(bal < limit)

amt += charge ;

return amt ;

}

return 0 ;

}

public String toString() {

return super.toString() + "Minimum balance before a charge:" + limit + " and Charge per check if balance falls below the minimum balance:"+charge;

}

double getLimit() {

return limit;

}

double getCharge() {

return charge ;

}

}

NOTE : I didn't provide output. because there is no information for what to do in main method. They only asked implement the above classes.

Add a comment
Know the answer?
Add Answer to:
code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Requirements:  Your Java class names must follow the names specified above. Note that they are...

    Requirements:  Your Java class names must follow the names specified above. Note that they are case sensitive. See our template below.  BankAccount: an abstract class.  SavingAccount: a concrete class that extends BankAccount. o The constructor takes client's firstname, lastname and social security number. o The constructor should generate a random 6-digit number as the user account number. o The initial balance is 0 and the annual interest rate is fixed at 1.0% (0.01).o The withdraw method signature...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes...

    According to the following information, define Account, CheckingAccount, and TestPart1 classes. 1. Account and CheckingAccount classes Account - number: int - openDate: String - name: String - balance: double + Account(int, String, String, double) + deposit(double): void + withdraw (double): boolean + transferTo(Account, double): int + toString(): String CheckingAccount + CheckingAccount(int, String, String, double) + transferTo(Account, double): int Given the above UML diagam, define Account and CheckingAccount classes as follow: Account (8 points) • public Account(int nu, String op, String...

  • TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static...

    TASK 1 Create a new class called CheckingAccount that extends BankAccount. It should contain a static constant FEE that represents the cost of clearing onecheck. Set it equal to 15 cents. Write a constructor that takes a name and an initial amount as parameters. Itshould call the constructor for the superclass. It should initializeaccountNumber to be the current value in accountNumber concatenatedwith -10 (All checking accounts at this bank are identified by the extension -10). There can be only one...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Language: C++ Create an abstract base class person. The person class must be an abstract base...

    Language: C++ Create an abstract base class person. The person class must be an abstract base class where the following functions are abstracted (to be implemented in Salesman and Warehouse): • set Position • get Position • get TotalSalary .printDetails The person class shall store the following data as either private or protected (i.e., not public; need to be accessible to the derived classes): . a person's name: std::string . a person's age: int . a person's height: float The...

  • The following class diagrams are designed for a restaurant that also provides home delivery services. Study...

    The following class diagrams are designed for a restaurant that also provides home delivery services. Study the given class diagrams, additional information and answer questions that follow: MobileContract PhoneModel planID string f contractiD: string modelNumber: int colour: string marketPrice: double phone: PhoneModel + MobileContract(string, string PhoneModel) +display: void + calcPlanPhonePrice: double + PhoneModel int, string, double) +display) void +getMarketPrice): double act rsPhoneDiscount: double + RoadshowContract(string, string PhoneModel, double) +display: void +calcPlanPhonePrice):double Additional Information: Class MobileContract string. Constructor. The are, Plan...

  • he class definition for a Hank Account class, contains the following private data nembers: the name,...

    he class definition for a Hank Account class, contains the following private data nembers: the name, account number (both are character arrays of 30 elements each) alance, and interest rate Cbolth are double). It also have the following public member unctions Bank AccountO: This function is the default constructor. deposito: subsequently adjusts the balance. (balance- balance + amt) withdrawo: This function is passed an amount to withdraw and subsequently adjusts the balance. (balance balance- amt). cale interestO: This function calculates...

  • For this lab you must write a complete class in C++. This will be a class...

    For this lab you must write a complete class in C++. This will be a class named BankAccount. This class must have the following private variables: 1. accountHolderName : string 2. balance : double 3. interestRate: double This class must have the following public constructor: 1. BancAccount(name : string, balance : double, rate : double) This class must have the following public member functions: 1. getAccountHolderName() : string a. returns the account holders name 2. getBalance() : double a. returns...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT