Question: Write a Java program. Create a BankAccount Class with balance (double) field. Add two methods (1) deposit(double amount) and (2) withdraw(double amount). Create two Runnable

Write a Java program. Create a BankAccount Class with balance (double) field. Add two methods (1) deposit(double amount) and (2) withdraw(double amount).

Create two Runnable classes (1) Deposit and (2)Withdraw.

Write a BankAccountTest prorgam (with main() method) that will use the above classes and ask user to choose Deposit or Withdrawal and the amount or exit program.

Deposit and Withdrawal tasks MUST BE DONE in different threads. Make sure that the program is thread-safe and one will not overwrite the other in performing the task. You can make the threads sleep between tasks for a random amount of time between 0 and 5000 millisecs.

After each taks display the balance to show that the balance correct.

Sample output is shown below.

---------Correct Sample Output -------------

Depositing 100.0 -> balance = 100.0 Withdrawing 100.0 -> balance = 0.0 Depositing 100.0 -> balance = 100.0 Depositing 100.0 -> balance = 200.0 Depositing 100.0 -> balance = 300.0 Depositing 100.0 - balance = 400.0 Withdrawing 50.0 -> balance = 350.0 Withdrawing 100.0 -> balance = 250.0 Withdrawing 100.0 -> balance = 150.0 Depositing 100.0 -> balance = 250.0

Terminating.....

--------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!