Add a toString method to your Account class. For the purposes of this assignment, please use the toString display the following: This account contains $x. You have earned $y in the last month. where x is the account balance (please don't format the decimals) and y is the monthly interest earned, obtained from the getMonthlyInterest method. Compile and test in a driver by creating and printing an Account object. Add an equals method to your Account class. Two Account objects are equal if their balance and annualInterestRates are equal. Compile and test in your driver by creating 2 Account objects to see if they are equal.
-
Add a toString method to your Account class. For the purposes of this assignment, please use the toString display the following:
This account contains $x. You have earned $y in the last month.
where x is the account balance (please don't format the decimals) and y is the monthly interest earned, obtained from the getMonthlyInterest method.
-
Compile and test in a driver by creating and printing an Account object.
-
Add an equals method to your Account class. Two Account objects are equal if their balance and annualInterestRates are equal.
-
Compile and test in your driver by creating 2 Account objects to see if they are equal.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 3 images
In Java Language
Create a CheckingAccount class to represent a checking account This class inherits from the Account class that you've created so far and has one new attribute, the overdraft limit, specifying how much the account can be overdrawn by. For example, if you have $100 in the account and you try to withdraw $150. This would be fine, if your overdraft limit was $50, meaning you can overdraw your account by $50 without penalty.
Note: All you're doing at this stage is creating the limit, don't worry about dealing with the overdraft yet. You just want a variable at this stage.
Your CheckingAccount class should also have getters and setters for the overdraft attribute and a constructor, but keep in mind how constructors work with inheritance.
No other methods or adjustments are to be made at this time.
Write a driver (or use your existing one) to test your CheckingAccount class by creating at least 1 instance and printing out its overdraft limit by using the getter.
IN JAVA LANGUAGE
Write an ATM class with an ArrayList of Account objects as an attribute.
In the constructor, add 3 Account objects to your ArrayList. They can all have a start balance of $100 and an annual interest rate of 0.12.
Include two methods, menu and makeSelection as outlined below. Please note that since both methods get user input, create a Scanner attribute to use in both.
menu method
This method does not have any parameters and does not return a value.
It should:
-
Get the account number from the user. This corresponds to the index of the items in the ArrayList. Since there are 3 elements in your ArrayList, you are going to ask them for a number between 1 and 3, but keep in mind that the indices of the ArrayList are 0-2, so you'll have to adjust the value you get from the user accordingly.
-
Present the user with a main menu as shown below:
-
Get their menu selection
-
Call the makeSelection method, passing it the account index obtained in step 1 and the menu selection obtained in step 3.
If you like, you can make steps 2-4 loop until the user's input is 4, but it is not necessary.
makeSelection method
This method does not return a value and has 2 parameters: the account index (you can just call it index) and the user's menu selection (you can just call it selection).
-
If the selection is 1, display the balance of the given account index.
-
If the selection is 2, get the amount to deposit from the user and deposit it into the given account index.
-
If the selection is 3, get the amount to withdraw from the user and withdraw it from the given account index.
-
If the selection is 4, exit the program by using the following line of code System.exit(0); (more info here if you've not seen this line of code before).
Testing
To test your application, create a driver that:
-
creates an ATM object
-
calls the menu method of the ATM object created above.
Here is a sample run so you can get an idea of how it should work.
in the image.
Can you write it in JAVA
-
Add a toString method to your Account class. For the purposes of this assignment, please use the toString display the following:
This account contains $x. You have earned $y in the last month.
where x is the account balance (please don't format the decimals) and y is the monthly interest earned, obtained from the getMonthlyInterest method.
-
Compile and test in a driver by creating and printing an Account object.
-
Add an equals method to your Account class. Two Account objects are equal if their balance and annualInterestRates are equal.
-
Compile and test in your driver by creating 2 Account objects to see if they are equal.