Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a BankAccount class, which declares the following instance variables: accountNumber of type int, accountHolderName of type String, balance of type double, and accountType of

Create a BankAccount class, which declares the following instance variables: accountNumber of type int, accountHolderName of type String, balance of type double, and accountType of type enum.
The enum type AccountType should have two values SAVINGS and CHECKING.
Create a public method called deposit() that takes in an amount of type double as input and adds the amount to the current balance. This method should also return the updated balance.
Create another public method called withdraw() that takes in an amount of type double as input, checks if the withdrawal amount is less than the current balance, and if so, subtracts the amount from the balance. If the withdrawal amount is greater than the current balance, the method should return an error message "Insufficient balance".
Create a public method getAccountInfo() that returns the account information in the format "Account Number: xxxxx, Account Holder: John Doe, Account Type: SAVINGS/CHECKING, Balance: $xxxx.xx".
Finally, create a constructor method that takes in the account number, account holder name, initial balance and account type as input and initializes the corresponding instance variables.
In the BankAccount class, make sure to use the private access modifier for the instance variables, as this encapsulates the data and prevents outside classes from directly accessing and modifying them. This is a best practice for encapsulation in object-oriented programming.
In the BankAccount class, make sure to use the private access modifier for the instance variables, as this encapsulates the data and prevents outside classes from directly accessing and modifying them. This is a best practice for encapsulation in object-oriented programming.
Do you know what an enum is? Read this article:
Do you know what an enum is? Read this article:
Enumerated Types
Enumerated Types
Question 2
[25 pts]
[25 pts]
Create a BankAccountTest class that contains a main() method that instantiates an object of type BankAccount, with account number of 12345, account holder name of "John Doe", initial balance of $1000 and account type as SAVINGS. Then use the deposit() and withdraw() methods of the object to deposit $500 and withdraw $300. Finally, use the getAccountInfo() method to print the current account information.
Use the getAccountInfo() method to verify that the deposit and withdrawal actions are performed correctly and that the account information is updated accordingly.
Use the getAccountInfo() method to verify that the deposit and withdrawal actions are performed correctly and that the account information is updated accordingly.
Question 3
[25 pts]
[25 pts]
Add a method called transfer() to the BankAccount class, that takes in a amount and destinationAccount as input and transfer the funds from current account to destination account.
This method should return the balance of the current account after the transfer, also should check for the sufficient balance in current account before proceeding the transfer and if there is insufficient balance return an error message "Insufficient balance".
Modify the BankAccountTest class, so that it calls the transfer() method and prints the balance after transfer.
Make sure that the transfer() method updates the balance of both the current account and the destination account.
Make sure that the transfer() method updates the balance of both the current account and the destination account.
Question 4
[25 pts]
[25 pts]
Add a new class CheckingAccount that inherits from the BankAccount class, and has a double
instance variable overdraftLimit in addition to the variables inherited from the superclass.
Create a constructor for the CheckingAccount class that takes in the account number, account holder name, initial balance, account type and overdraft limit as input, and uses the super keyword to call the constructor of the superclass, passing in the account number, account holder name and initial balance, account type.
Re-write the withdraw() method in the CheckingAccount class so that it first checks if the withdrawal amount is less than the current balance plus the overdraft limit. If it is, the withdrawal is allowed and the balance is updated. If not, the method should return an error message "Insufficient funds".
Create a new method displayOverdraftLimit() that returns the overdraft limit of the CheckingAccount.
In the BankAccountTest class, create a new object of type CheckingAccount with account number 12345, account holder name "John Doe", initial balance $1000, account type as CHECKING
You will need to use the concepts of inheritance and the super keyword. Re-writing a method from parent class in a child class is called Method Overriding. We will discuss the details of Polymorphism in future sessions.
You will need to use the concepts of inheritance and the super keyword. Re-writing a method from parent class in a child class is called Method Overriding. We will discuss the details of Polymor

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

The Database Factory Active Database For Enterprise Computing

Authors: Schur, Stephen

1st Edition

0471558443, 9780471558446

More Books

Students also viewed these Databases questions

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago