Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: THEend8_
Smart Farms - Part 2
Introduction
The objective of this assignment is to extend the implementation of Assignment 1 using arrays and external files.
Before you start
Carefully read the specification below. Make sure you have all the information necessary to start writing the program. If you are uncertain of something, do not make assumptions. You can discuss those with your tutor during your lab.
Specification
The program will manage up to 3 farms. This must be done using an array to hold the farm sensors. Each farm will holdup to 4 types of sensors. This must also be done using an array.
When run, the program will display a menu of actions to the user, including one that exits the program. Until the user chooses to exit, the menu is displayed again after each action is completed.
The program should have the following functionalities:
1. A user may add a farm.
The user will specify the farm's name.
There should bean error message if the farm already exists, or if there are already 3 farms.
2. A user may remove a farm.
The user will specify the farm's name.
There should bean error message if the farm does not exist.
3. A user may add a sensor to a farm.
Normally, the user will specify the sensor's type, price, weight, and quantity in inventory, along with the farm's name (price, weight and quantity need to be positive, if not, the program will show a message and ask the input again). The sensor type can be Temperature, Pressure, Humidity, Soil Temperature, Soil Humidity or Soil PH.
If, upon being given a type, there is a sensor in any farm with that name, the program should indicate this. The user will then only be queried for a quantity and farm name. Other details will betaken from the existing sensor.
eg: Sensor exists, with price $ and weight . Adding additional sensors.
There should be an error message if the farm does not exist, or already holds 4 different types of sensors.
4. A user may remove multiple sensor items at once.
The user will specify a sensor type and a farm name, and a positive quantity.
There should be an error message if the sensor type does not exist in the farm, or the farm doesn't exist, or the number of sensors is less than the number to remove.
Otherwise, the quantity will be reduced by the specified quantity. After that, if the quantity of the sensor is zero, then the sensor should be removed from the farm.
There should be output indicating this.
eg: items of Sensor removed from farm
5. A user may query for a list of farms.
There should be output, describing the farms where the output must be alphabetically sorted using the farm names.
Normally, there should be one line per farm.
eg: Farm has sensors
If there are no farms, the output should be one line.
eg: No farms exist
6. A user may query for a list of sensors in a farm. The user will specify the farm's name. There should bean error message if the farm does not exist.
Otherwise, there should be output describing the sensors.
Normally, there should be one line per sensor.
eg: Sensor has price $, weight kg, and quantity If there are no sensors, the output should be one line.
eg: No sensors in farm
7. A user may query about a sensor's presence in the farms. The user will specify the sensor's name. There should bean error message if the sensor doesn't exist.
Otherwise, there should be one output line for each farm the sensor is in.
eg: Sensor is in farm with quantity
8. A user may query for the cumulative value of all sensors in a farm. The user will specify the farm name.
There should bean error message if the farm doesn't exist.
Otherwise, there should be output describing the cumulative value.
eg: Farm has cumulative sensor value $
As an example, let's say there exists a farm F1 containing sensors S1 and S2. S1 has price $10 and quantity 2. S2 has price $5 and quantity 100. The cumulative value of all sensors in F1 would be 10*2+5*100 = 520.
9. A user may export farm and sensor information to a file.
The created file should consist of zero or more lines, each of which should have one of these forms:
This indicates that a farm exists and holds a sensor with the specified details.
eg: newcastle-farm Temperature 20 100 10
This indicates that a farm exists, but specifies nothing about it's sensors. It should be output for empty farms.
An error message should be output if the file is unable to be created, or if a problem occurred during writing.
10. Exit the program.
Program Requirements
The program should consist of 3 classes:
. Sensor - stores the following details about a group of sensors.
。type - String – the type of the sensor. Must not contain spaces.
。price - double - the price of the sensor. Must be positive.
。weight - double - the weight of the sensor, in kilograms. Must be positive.
。quantity - int - the number of sensor items. Must be positive.
. Farm - stores the following details about a farm.
。name - String - the name of the farm. Must not contain spaces.
。sensors - array of Sensor with size 4 - the sensors held by the farm.
. Interface - provides the user interface.
。farms - array of Farm with size 3 - the farms managed by the program.
All data fields of your classes should be private (this is imposed so that you apply the principles of encapsulation).