首页 > > 详细

辅导 SENG6110 Programming Assignment 2 – Individual Assignment – Trimester 1 2024讲解 Java编程

SENG6110 Programming Assignment 2 – Individual Assignment – Trimester 1 2024

Due: By electronic submission (Canvas) by Friday Week 12 - 11:59pm on 19th  April

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).

IMPORTANT:

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. Template of Interface class is provided here:

public class Interface {

private void run(){

//...

}

public static void main(String[] args){

Interface infFace = new Interface();

intFace.run();

}

}

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. A more detailed marking schema will be made available on Blackboard.

What to submit

You should submit one compressed .zip file via the "Assignment 2" link on Canvas, which should have: Three .java files (Farm.java, Sensor.java, Interface.java). Do not include .class files in your submission.

Add your student name on the top of each Java file submitted.

/*Author: name

*Student No: XXXXXX

*Date: 02-03-2022

*Description:

*/

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.






联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!