FoodBank and RaceTrack Report


In this assignment, you will develop a C program to implement the “malloc”, “free”, “calloc” and “realloc”
1. Check out the malloc tutorial from Dan Luu on how these functions can be implemented at
The tutorial implements working versions of malloc, free, calloc and realloc and you can use that code as-is.
2. Write a driver function (i.e., main function) to demonstrate the usage and efficiency of these functions.
The main() should have at least 10 calls each to malloc, calloc, realloc and free. Set up the function to (i) print out
the heap start/end addresses and (ii) print out the memory leaks in your code. In your report, explain how you
calculated memory leaks in this case.
3. Your main task is to implement the exercises mentioned in the tutorial. These are also shown below:
(a) Convert the single linked list implementation of the tutorial into a doubly linked list version; make changes to
all the functions accordingly to work with the doubly linked list.
(b) The current implementation implements a first fit algorithm for finding free blocks. Implement a best fit
algorithm instead.
4. Your code must use the set-up mentioned in this tutorial. Other online resources can be consulted but
NOT copied. The tutorial mentions some other implementations for splitting/merging blocks that can only be
consulted but not copied.Assignment 8
Write the following Java programs and upload the FoodBank and RaceTrack files to Canvas
when the assignment is complete. Please note that the use of the stop and suspend methods are
prohibited for both programs. When doing this, please use Java 8 so that it works with
Note: The test cases require JUnit 4 (JUnit 5 will not work)
[40 points] Create a Java program that uses monitors to control access to a FoodBank object.
You will create a FoodBank class that has a food amount and methods to give and take food.
You will create two Thread classes for this program that will either put food into the food bank
or take food from the food bank. Food cannot be taken if there is no food available to take. This
is not a true producer/consumer problem. You only have one condition, which is to wait if there
is no food available to take. Both giving and taking food must involve locking the FoodBank
object and unlocking it when done. The FoodBank object must never enter an invalid state (a
negative amount of food) The methods in FoodBank to take and give food must print out exactly
what is happening with each action in the method, i.e. “Waiting to get food”, “Taking 10 items
of food, the balance is now 20 items”. NOTE: No other methods can print to the console.
A class FoodBank
FoodBank will have a single instance variable named food of type int. FoodBank will
define a default constructor which initializes food to zero. FoodBank will have two methods:
giveFood and takeFood. Both methods will have a single parameter of type int. giveFood will
add the value of the parameter to the food instance variable, takeFood will subtract the value.
A class FoodProducer
FoodProducer will have a single instance variable named bank of type FoodBank.
FoodProducer will have a parameterized constructor with a single parameter of type FoodBank.
The parameterized constructor will initialize the value of bank to the single parameter.
FoodProducer will extend the Thread class and override Thread’s run method. FoodProducer’s
run method will loop infinitely. On each loop iteration run will generate a random number from
1-100 and add that much food to the bank instance variable. After adding food, the thread will
sleep for 100 milliseconds.
A class FoodConsumer
FoodConsumer is identical to FoodProducer except that the random number generated in
run will be removed from the FoodBank object.
A class FoodBankPatrons
FoodBankPatrons will have a main method in which a FoodBank, FoodProducer, and
FoodConsumer object are created. The FoodProducer and FoodConsumer must share the same
FoodBank object. Once created, the main method starts these threads.
[60 points] Create a Java program which will use multiple threads to simulate a race between
cars. The program should look like:
Create a class RaceTrack which uses JavaFX* (subclasses the Application class) and overrides
its start method to do the required drawing. Each car must be advanced by a separate Thread. On
each thread iteration, each car should advance a random 0-10 pixels forward. Once advanced, a
thread should sleep for 50 miliseconds. The threads will execute until a car reaches the end of the
track. Once this occurs, an Alert should be spawned alerting the user of the winner and all cars
stop. The primaryStage will be 500px by 200px and is not be resizable.
Please make the filepath for the car image a constant defined at the beginning of your file so I can easily modify it for grading. (Or leave a comment indicating that the
image path is a working web URL instead)
HINT: Updating the GUI from a non-GUI thread is considered bad practice as it leads to race
conditions and UI errors. If you need to update a GUI component from a non-GUI thread, please
use the runLater method defined in the Platform class; only update the GUI with runLater (it will
spin off its own thread). Don’t be dissuaded by the “future time” a runnable object passed to
runLater will be executed. We can expect that any runnable object passed to runLater will be
executed quickly enough for the purposes of this project.
*Java 8 comes with JavaFX and should work out of the box and you should be using Java 8. For
all later Java versions, you must install JavaFX. Instructions can be found here. Please note that
the provided URL has instructions for installing JavaFX both on a system and for specific IDE’s,
including Intelji. It is recommended you follow the tutorial for the specific IDE you are using.
Grading Rubric for FoodBank:
Classes defined correctly
Correctly uses Java object monitors to enforce
mutual exclusion
FoodBank state remains valid even with
multiple Consumer threads active
Grading Rubric for RaceTrack:
GUI Implemented correctly
Each car is run by a separate thread
Start button works as described
Winner is random and stops race from
Pause button works as described
Reset button works as described

Purchase answer to see full

We offer the bestcustom writing paper services. We have done this question before, we can also do it for you.

Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.