Question: Java Help: This is part 3 of a 5 part question so 5 likes on offer. Part 1: https://www.chegg.com/homework-help/questions-and-answers/java-help-part-1-5-part-multithreading-question-5-likes-offer-part-2-https-wwwcheggcom-hom-q69755166 Part 2: https://www.chegg.com/homework-help/questions-and-answers/java-help-part-2-5-part-question-5-likes-offer-part-1-part-3-part-4-part-5-part-done-2nd-p-q69755173 Part 4: https://www.chegg.com/homework-help/questions-and-answers/java-help-part-4-5-part-question-5-likes-offer-part-1-part-2-part-3-part-5-part-done-4th-p-q69755207
Java Help: This is part 3 of a 5 part question so 5 likes on offer. Part 1:
https://www.chegg.com/homework-help/questions-and-answers/java-help-part-1-5-part-multithreading-question-5-likes-offer-part-2-https-wwwcheggcom-hom-q69755166
Part 2:
https://www.chegg.com/homework-help/questions-and-answers/java-help-part-2-5-part-question-5-likes-offer-part-1-part-3-part-4-part-5-part-done-2nd-p-q69755173
Part 4:
https://www.chegg.com/homework-help/questions-and-answers/java-help-part-4-5-part-question-5-likes-offer-part-1-part-2-part-3-part-5-part-done-4th-p-q69755207
Part 5:
https://www.chegg.com/homework-help/questions-and-answers/java-help-part-5-5-part-question-5-likes-offer-part-1-part-2-part-3-part-4-part-done-last--q69755214
This part should be done 3rd. Please use Book.java and Bookstore.java from prior part solutions.
Part 3: Buyer.java
This class will represent customers who wish to buy books from the Bookstore. Each instance of Buyer will run as a separate thread, and so the Buyer class should implement the Runnable interface. Each Buyer instance should be assigned a unique ID when it first tries to interact with the Bookstore (i.e. when its run() method is called). This unique ID should be stored in a private integer field. Static thread safe fields (e.g. instances of AtomicInteger) should be used to count the total number of buyers created, and the total number of purchases successfully completed.
The Buyer constructor should accept an instance of Bookstore as an argument, and then store the reference to this object in a private field. The Buyer run() method should attempt to buy a Book from the store. It should first check that there is at least one Book available to buy in the store (by calling the isEmpty() method of the BookStore instance). If there are no books available, the Buyer should wait until a book becomes available before proceeding. The Buyer should then proceed to take a book from the BookStore using the takeBook() method. Once a Buyer has successfully completed a purchase, its run() method can terminate (i.e. the thread has finished its work). Some of the operations in the run() method will need to be made be made thread safe to prevent race conditions (e.g. two buyers trying to buy the same Book). Your answer should use the wait() and notify()/notifyAll() methods.
A message should be printed to the console each time a new Buyer reaches the store (directly after its run() method is called), each time a Buyer waits to buy a Book, and each time a Buyer successfully buys a Book from the Bookstore (see example program output in part 5).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
