SENG6110 Object Oriented Programming
Programming Assignment 1 (individual assessment) T1, 2024
Due: Online submission on Canvas by 11:59pm on 22 March 2024
Smart Farms
Introduction
The objective of this individual assignment is to implement an object-oriented program using Java, to manage environmental sensors at smart farms. Assignment 2 will bean extension of this assignment.
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. Post your questions to the discussion board forum named "assignment 1" and check it regularly.
Try to start the assignment as soon as possible. There is a document “HelpToStartAssign1” and some Java files on Canvas, which you can use as a starting point.
Specification
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 will keep track of up to 2 farms, and each farm will be able to have up to 3 sensors.
The program should have the following functionalities:
1. A user may add a farm.
The name of the first farm must be farm1 + YOUR LAST NAME and the name of the second farm must be farm2+ YOUR LAST NAME. For example if your last name is “Smith” then the name of the farms must be farm1Smith an farm2Smith.
There should bean error message if there are already 2 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 type, price, weight, and quantity, 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 of that type, 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: Temperature sensor exists, with price $<price> and weight <weight>. Adding additional items. There should be an error message if the farm does not exist, or already holds 3 different types of sensors.
4. A user may remove one sensor from a farm.
The user will specify a sensor type and a farm name.
There should bean error message if that sensor does not exist in that farm, or the farm doesn't exist. Otherwise, the quantity will be reduced by 1. 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: One Temperature sensor removed from farm1Smith
5. A user may query for a list of farms.
There should be output, describing the farms.
Normally, there should be one line per farm.
eg: farm1Smith has 20 sensors
If there are no farms, the output should be one line.
eg: No farm exist
6. A user may query for a list of sensors at a farm. The user will specify the name of the farm. 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: Temperature sensor has price $<price>, weight <weight>kg, and quantity <quantity> If there are no sensor, the output should be one line.
eg: No sensors at farm
7. A user may query about a sensor at a farm. The user will specify the sensor type. 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: Temperature sensor is at farm1Smith with quantity 20
8. A user may query for the total number of sensors in a farm and total cost. The user will specify the name of farm.
There should bean error message if the farm doesn't exist.
Otherwise, there should be output describing the number of sensors and total cost at that farm. eg: farm1Smith has 30 sensors of value $4000
As an example, let's say there exists a farm farm1Smith containing Temperature and Pressure sensors. Temperature sensor has price $10 and quantity 2. Pressure sensor has price $5 and quantity 100. The total number is 102 and total value of all sensors at farm1Smith would be 10*2+5*100 = $520.
Program Requirements
The program should consist of 3 classes:
. Sensor- stores the following details about a group of sensor items.
o type - String - the type of the sensor (must be Temperature, Pressure, Humidity, Soil Temperature, Soil Humidity or Soil PH.
o price - double - the price of the sensor. Must be positive.
o weight - double - the weight of the sensor, in kilograms. Must be positive.
o quantity - int - the number of sensors. Must be positive.
. Farm - stores the following details about a farm.
o name - String - the name of the farm.
o sensor1, sensor2, sensor3 - up to 3 Sensor objects.
. Interface - provides the user interface.
。 farm1, farm2 - up to 2 Farm objects.
All data fields of your classes should be private (this is imposed so that you apply the principles of encapsulation).
Your classes will also need methods to provide the required functionalities. The only class which should have a main method is Interface.java, which should create an instance of the class Interface, and call a method run(), which will display the menu to the user. This class will be the only one that takes input from and sends output to the user using GUI methods. A template is shown below.
public class Interface {
private void run(){
//...
}
public static void main(String[] args){
Interface intFace = new Interface();
intFace.run();
}
}
You must not use arrays in this assignment.
Marks will be awarded for layout (including visual aspects (variable names, indentation) and structural aspects (variable scope, method usage)), documentation (comments), and the submission's ability to perform as specified. Template files are provided on Canvas. A more detailed marking schema will be made available on Canvas.
What to submit -- IMPORTANT
You should submit in a compressed .zip file, via the "Assignment 1" link on Canvas:
• only the three .java files (Sensor.java, Farm.java, Interface.java)
• and a word document that contains an assignment cover sheet and UML diagram,
Do not include .class files in your submission. Add the name of the student on the top of each Java file submitted.
Late Penalty and adverse circumstances
Note that your mark will be reduced by 10% for each day (or part day) that the assignment is late. This applies equally to week and weekend days. You are entitled to apply for special consideration if adverse circumstances have had an impact on your performance in an assessment item. This includes applying for an extension of time to complete an assessment item. See
https://www.newcastle.edu.au/currentstudents/learning/assessments-and-exams/adverse- circumstances for more details.
版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。