Solution for Assignment 2
First let’s start off with the solution for assignment 2 before we jump into our next assignment.
Click Here to download the source files for assignment 2’s solution
For your viewing pleasure, here’s the video walk-through for assignment 2 as well:
Requirements for Java Practice Assignment 3
In this weeks Java practice assignment, your job is to implement the simulation of an assembly line that will build Cars. Each Car is made up of several components: tires, seats, engine and frame. Each of these components takes a different amount of time to build on their own. Here’s the breakdown on the simulated time each component takes to construct:
- Tire – 2 seconds
- Seats – 3 seconds
- Engine – 7 seconds
- Frame – 5 seconds
With these times, you must implement the code that will simulate the construction of each of these components individually, then once all the necessary components are built you must put them together to make a car. To build a car, you’ll need 4 tires, 5 seats, 1 engine and 1 frame. Here’s the catch, the assembly line can only and should only be capable of building 3 Components at any given time. You’ll need to implement this in your code.
Once you’ve completed the assignment and all unit tests are passing, try and fiddle with the order of which the Components are assembled on the line. Is there a particular order that provides the fastest building time for a Car?
Click here to view the source files on GitHub
And as always, here’s the GitHub Clone URI:
This assignment deals with multithreading and the singleton design pattern. Be sure to read up on these two articles before you try to complete the assignment:
If you encounter strange issues, just think in terms of the fact that you have multiple threads running at the SAME TIME doing their thing. Most problems can be solved by realizing this, and understanding exactly what’s going on in the code. I would recommend the use of plenty of
System.out.println() statements to be used as logging so you can get a picture of what exactly is happening at any given moment.
Hint: if you are struggling to make the very last unit test pass, do some research on the synchronized keyword.
Best of luck and if you are really really stuck, just post a comment below. Also, if you see a question from another reader, and you know the answer, feel free to jump in and contribute