Answered step by step
Verified Expert Solution
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: SAVINGSCHECKING Balance: $xxxxxx
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 objectoriented 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 objectoriented programming.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started