Assignment 5
Working in pairs
For this assignment, you are allowed to work in pairs. Prof. Manzara said in lecture to pick partners within your tutorials, so please do not pair up with someone from another section.
Submitting and grading for Assignment 5
You will be required to demo your assignment to me either in tutorials or most likely outside of class. I will send out a signup sheet near the end of the week, before the last week of classes. In addition, you must still submit your assignment. If you are working in pairs, please have one member submit the assignment on D2L, and include the name and ID of the other student.
Starting assignment 5
Last week's tutorials were all about getting you started for A5, but if you didn't attend class... . . .
Step 1 should be reading over the assignment. Make note of what UI elements, inputs, and outputs are required.
Step 2 should be to draw a quick sketch of your UI on paper, so you have a blueprint to go by. It's much easier to visualize than the first page of your assignment outline, and you won't miss anything this way. Do not spend more than 5-10 minutes on your sketch, it's supposed to be quick and simple. You can change borders, margins, colors, fonts, etc. AFTER you have done your assignment.
In class, I recommended using the MVC pattern for each of the four parts in your program: temperature, soil moisture, humidity, and environment. Each part will be in its own thread, and has little to no interaction with the other parts, therefore it will be much easier to manage if you separate them. Put each of the four parts into its own JPanel, and then when you run your program, add all the panels to your JFrame. Yes, this will mean you have 12 files right from the beginning, plus another file to run your program and set up each JPanel. I suggest you write the code for one panel first, such as temperature, before doing the other panels. Your code will be extremely similar, and you'd rather copy your own code after it's working.
Tip: Name your variables and UI elements well. If you do, and you follow the advice above, you can use search and replace:
Temperature class:
- currentTemp
- desiredTemp
- lblCurrentTemp
- txtCurrentTemp
- lblDesiredTemp
- txtDesiredTemp
- .....
Humidity class: search for "Temp" and replace with "Humidity", search for "temp" and replace with "humidity".
Setting up your UI is important, but it's not worth very much for this assignment. Don't spend too long here.
The Controller classes will be very similar to what you have already done in A4. However, because we want each sensor to run independently in its own thread, we have to extend Thread with our Controllers. Each Controller will have a Run() method where you put your code for controlling the simulation of that sensor. For example, if I set the temperature sensor to update in 3 second intervals, then in Run() I will have a loop which updates the temperature every 3 seconds. This can be done by making the thread do nothing or sleep for 3 seconds.
Below is an example of what the UI may look like. You are free to follow this layout, but I encourage you to draw up your own. My UI has 54 elements.