In this lab you will create small Java applications by using as reference an UML class diagram. Please consider following general notes before start implementing:
- toString() method when required will return a string like ClassName{attributeName1=attributeValue1,...,attributeNamen=attributeValuen}.
- Do not reuse (import) the same class in multiple exercises. Each exercise is standalone and should be resolved in its package.
- Create any additional constructors, getters and setters needed by your [unit] tests.
This exercise demonstrate concepts you will need to apply in this lab. Solution for this diagram can be found in source folder in package isp.lab4.exercise0.
NOTE: This exercise do not require any implementation from student.
The following exercises model the control of a fish aquarium, step by step
Given the UML class diagram above, implement the corresponding Java program.
- Create Java class based on the diagram above.
- Instantiate and test created class in the provided Exercise 1 main method.
- Create a minimal unit test for testing the behavior of the created class.
The automatic fish feeder is a very useful addition to any aquarium. Our fish feeder has two operations and a maximum capacity of 14 meals. Once the fill up operation is called, the meals attribute has to be reset to 14 and a message should be displayed in the console. The feed operation will decrease the number of meals by 1, and will also display a proper message into the console.
- Create Java class based on the diagram above.
- Instantiate and test created class in the provided Exercise 2 main method.
- Create minimal unit tests for the behavior of the created classes.
Now let's assemble the two components. Each time the current time is modified (i.e. setCurrentTime() is called), the controller checks if it's feeding time. If it is, then it triggers the feed operation. The time is represented as a flot, e.g. 2.30 or 14.50 (ignore validation errors for now).
- Create Java classes based on the diagram above.
- Instantiate and test created classes in the provided Exercise 3 main method.
- Create minimal unit tests for the behavior of the created classes.
Extend exercise 3 and implement the aquarium's lights control. Algae can be a real problem in any aquarium, and to much light time will boost their growth. But if the plant don't get enough light they will die. Keep the lights on anywhere between 6 to 8 hours per day. You need to add 2 new attributes for: lightOnTime and lightsOffTime. Also add a new class called Lights that has a boolean attribute isOn and two methods turnOn() and turnOff(). Like in the case of the previous exercise, turning the lights on/off is determined when setting the current time in the controller.
- Update the class diagram from exercise 3 with the newly added subsystem. The docs directory contains the StarUML model. You can use it to modify ex3 diagram. Export it as ex4.jpg and add the image to docs.
- Create Java classes based on your new diagram.
- Instantiate and test created classes in the provided Exercise 4 main method.
- Create minimal unit tests for the new behavior.
The water temperature is not very important for the majority of the plants, but it is for the fish. For tropical fish species somewhere between 24-27°C is recommended. We also want a leak detection subsystem.
- Create Java classes based on the diagram above.
- the controller checks the water level; if it's below the preset value it turns on the alarm.
- the controller checks the temperature; if it's below the preset value it turns on the heater; if the temperature equals the preset value, it turns the heater off.
- Instantiate and test created classes in the provided Exercise 5 main method.
- Create minimal unit tests for the new behavior.
Modify exercise 5 and add pH monitoring/control. Determine if it's possible to change the water pH without killing the fish. If it can be done implement the control. If not, only raise an alarm.
- Create the new class diagram.
- Implement the code and the unit tests.