Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IT-162 Java 2 Homework: Multithreading Apply your knowledge of using multithreading and synchronization in Java. Submit the project.zip via Blackboard. Create a program that uses

IT-162 Java 2

Homework: Multithreading

Apply your knowledge of using multithreading and synchronization in Java. Submit the project.zip via Blackboard.

Create a program that uses multithreading and synchronization.

With multithreading, the results may be different each time based on system resource usage. For example, you share a checking account with another person and both of you have ATM cards. The shared account has $100 in it. If both try to withdraw $100 at the same time at two different locations, the first transaction gets locked (if it is properly programmed with synchronized). The second transaction will not be able to overdraw the account either. Therefore, you need to understand how and when to use synchronized.

Create Java project Week04Multithreading. Create ProcessBankAccount.java to demonstrate how to do bank account deposits and withdrawals. Create Account.java for the account transactions. This application will simulate two ATM cards for one bank account. This is a shared account owned by Jade and Rocket. Each person will make 5 withdrawals of $100 each. Each person will make 1 deposit of $200 each. Only one person can withdraw money at a time.

ProcessBankAccount.java must have the following methods: main, run, makeWithdrawal, makeDeposit. This class implements Runnable. (40 points)

main: This contains the BankAccount object, two threads, sets names, and starts threads. Create a new instance of the BankAccount. Set the names of the threads. One thread will be you and the other thread will be your friend, Bob. Start both threads.

run: This prints the starting balance with the name of the thread. It must loop 5 times to make the $100 withdrawal. If the account balance is negative, send a message ThreadName account is overdrawn. After the withdrawal processing is complete, make a $200 deposit.

makeWithdrawal: This will process withdrawal transactions. This needs to be synchronized to avoid withdrawing more money than the account has available. Check the balance of the account before the person makes the withdrawal. Print the balance of the account after the withdrawal. If the withdrawal cannot be made, send the following error message Not enough in account for ThreadName to withdraw, account balance is account balance. Put a thread sleep in this method Thread.sleep(100);.

makeDeposit: This will process deposit transactions. Use the type of logic for deposits by creating a makeDeposit method. You do not need to synchronize this method. This method will output: ThreadName is going to add money deposit and ThreadName completes the deposit deposit balance is account balance. Put a thread sleep in this method Thread.sleep(100);.

Account.java contains the initial balance of 500 and the following methods getBalance, withdraw, and deposit. (10 points)

Be sure the program checks for other error processing as necessary. (10 points)

The program must follow proper naming conventions of this course. (10 points)

Test the program and provide a print-screen of the test results. (10 points)

Be sure to have the proper program documentation/comments. All methods must have the proper JavaDoc comments. (10 points)

Generate a JavaDoc for your Project. You do this by selecting your project folder, select Project, Generate JavaDoc. You can refresh your project to see the doc folder that contains your index.html. Select Open With, Web Browser, navigate to annotations and provide a print-screen with your submission. (10 points)

Refer to the practice exercise for tips on how to create this application.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

Students also viewed these Databases questions

Question

Writing a Strong Introduction

Answered: 1 week ago