Q2
Q.2 An irrigation system for a greenhouse controls a sprinkler system which uses the moisture content of the soil as input. The moisture content of the soil is based on readings from 4 probes. The sprinkler has 3 different settings that determine the amount of water that is sprayed per hour. The moisture content is measured to the nearest mm.
Write and test a program that accepts the four readings (array of type int) and returns the sprinkler setting (int), based on the average of the four readings. You only need to use data types int in the calculation and allow the averaged value to be rounded down.
| Average Moisture Content (in mm) | Sprinkler Setting |
|---|---|
| 0-50 | 2 |
| 51-100 | 1 |
| 101-150 | 0 |
Table 1: Sprinkler Setting
(handwritten note: array size == 4)
Program
Write a java class called SoilMonitor.java and a test class SoilMonitorTest.java in a package called com.ait.monitor.
- ▾ 📦 com.ait.monitor
-
📄 SoilMonitor.java
-
📄 SoilMonitorTest.java
SoilMonitor.java contains one method called moistureLevelCheck that takes an array with four sample values of type int. SoilMonitor.java averages the four sample values and returns an int the value of which corresponds to the sprinkler setting based on Table 1 above.
public int moistureLevelCheck(int[] moistureContent) {
Exceptions (IllegalArgumentException) with slogan "System Faulty" should be used if:
- ✓ Any value in the samples array is less than 0 and greater than 150.
- ✓ The number of elements in the array is not equal to 4.
Using equivalence partitioning and boundary value analysis identify the equivalence partitions and boundary values (using 3-value analysis) that you would explore for this scenario. Write the values into the sheets provided and write the code for SoilMonitor.java and SoilMonitorTest.java