Question: Java programming: Create a class called BankAccount with the following variables and methods Variables A string variable called acctHolderFirstName - This will be used to
Java programming:
Create a class called BankAccount with the following variables and methods
Variables
- A string variable called acctHolderFirstName - This will be used to store first Name of the account holder
- A string variable called acctHolderLastName This will be used to store last Name of the account holder.
- A double variable called acctBalance - This is used to store account current balance.
- A String variable called acctType - This will hold the account type. (Checking or Saving)
Methods
- A Default Constructor
This method will do the following
- Initializes acctBalance to have a value of zero
- Sets the acctType to Checking
- Calls method getAccountInfo();
- An overloaded Constructor that takes 4 parameters
( firstName, lastName, Balance , Type)
This method will the followings
Sets acctHolderFirstName to firstName
Sets acctHolderLastName to lastName
Sets acctBalance to balance
Sets acctType to Type
- A method called getAccountInfo()
This method prompts the user for First Name, Last Name, and account Type.
It initializes the class variables to values user provides.
- A method called Deposit()
This method asks the user to enter a double amount to deposit into acct
It adds the amount the current balance and updates the current balance amount.
- A method called displayBalance()
This method displays the following information
Account Holder Last Name
Account Type
Current Balance in the account
Testing Your Code
Create a class called TestAccountBalance
Instantiate a BankAccount Object called RonaldoAccount as described below
- Use the default constructor to create the object, and provide the following values
- First Name = Cristiano
- Last Name = Ronaldo
Using the hisAccount object call its member functions
Call DisplayBalance()
Call Deposit(), and deposit $255 into account
DisplayBlance()
Instantiate a BankAccount Object called KaylynAccount as described below
- Use the overloaded constructor to create the object, and provide the following values
- First Name = Kaylyn
- Last Name = Kyle
- Balance = 895
- Acct Type = Saving
Using the herAccount object to call its member functions
Call DisplayBalance()
Call Deposit(), and deposit $105 into account
DisplayBlance()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
