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.

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter4: More Object Concepts
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
  1. 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.

  2. Compile and test in a driver by creating and printing an Account object.

  3. Add an equals method to your Account class. Two Account objects are equal if their balance and annualInterestRates are equal.

  4. Compile and test in your driver by creating 2 Account objects to see if they are equal.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

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.

Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

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:

  1. 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.

  2. Present the user with a main menu as shown below:

 

  1. Get their menu selection

  2. 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).

  1. If the selection is 1, display the balance of the given account index.

  2. If the selection is 2, get the amount to deposit from the user and deposit it into the given account index.

  3. If the selection is 3, get the amount to withdraw from the user and withdraw it from the given account index.

  4. 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:

  1. creates an ATM object

  2. 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.

Enter an account number. 1 - 3: 2
Main Menu:
1: check balance
2: deposit
3: withdraw
4: exit
1
The current balance is $100.0
Main Menu:
1: check balance
2: deposit
3: withdraw
4: exit
2
Enter the amount to deposit: 100
Main Menu:
1: check balance
2: deposit
3: withdraw
4: exit
1
The current balance is $200.0
Main Menu:
1: check balance
2: deposit
3: withdraw
4: exit
4
Transcribed Image Text:Enter an account number. 1 - 3: 2 Main Menu: 1: check balance 2: deposit 3: withdraw 4: exit 1 The current balance is $100.0 Main Menu: 1: check balance 2: deposit 3: withdraw 4: exit 2 Enter the amount to deposit: 100 Main Menu: 1: check balance 2: deposit 3: withdraw 4: exit 1 The current balance is $200.0 Main Menu: 1: check balance 2: deposit 3: withdraw 4: exit 4
Solution
Bartleby Expert
SEE SOLUTION
Follow-up Question

Can you write it in JAVA programming language

  1. 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.

  2. Compile and test in a driver by creating and printing an Account object.

  3. Add an equals method to your Account class. Two Account objects are equal if their balance and annualInterestRates are equal.

  4. Compile and test in your driver by creating 2 Account objects to see if they are equal.

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
void method
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage