COSC1519 Introduction To Programming
Assignment 2: Object Oriented OffGridManager (20 marks)
In this assignment you will create an application that allows an off-the-grid user to manage their
electrical devices (similar to HomeAutoBot) and manage power production/consumption need.
2.1 Functional Requirements
The marks for functional requirements are approximately equally divided between each of the
following functional criteria (given in bold).
The main window of the application: Must have the following elements (you are free to re-order
them as you wish)
‘Current power position (Watts)’ field: This is not a value that should be entered directly. It is
calculated and updated based on what power generating devices and what power consuming devices
are currently turned on/off. When a power generating device is turned on/off, this value must
increase/decrease by the rated power of that device. When a power consuming device is turned on/off,
this value must decrease/increase by the rated power of that device. The program must not allow the
user to turn on power consuming devices or turn off power consuming devices that would result in the
power position becoming negative. (The power position must be zero when all devices are turned off.)
‘Add device’ button: Allows the user to add an electrical device that either uses energy or produces
energy. First, the user selects an image of the device and the name of the device is extracted from the
filename. Then the user must enter its power rating in Watts (a negative input here means it produces
electricity). It is then added to the list (the grey area in the illustration above). At first, the device is
turned off and therefore it does not affect the power position. Finally, a separate GTerm window must
be created for the device, showing its name, on/off status, rated power production/consumption figure
‘Remove device’ button: Allows the user to remove the device that is currently selected in the list.
Before removal, the device must be turned off and if the removal of a currently turned on power
generating device would result in a negative power position, the user must be told that they cannot
remove the device. Additionally, the program must gracefully handle situations where the user selects
this button without selecting an item from the list.
‘Toggle on/off’ button: Allows the user to turn on the selected device if it is currently turned off or
turn off a device that is currently turned on. The on/off status of that device must be shown in that
device’s window. Your code must ensure that the power position is correctly maintained (refer to
description for ‘current power position’ field).
Device list: This list shows only the names of the devices that are currently in the system. These
devices may be turned on or off. Selecting devices on this list is necessary before the user is allowed to
toggle on/off or remove a device.
The example above shows how two solar panels with a total power production of 1000 Watts is used to
power the kettle which consumes 1000 Watts (power position is 0). Note the washer cannot be turned
on without turning the kettle off in the above scenario or without adding more power generating
devices. The solar panels cannot also be removed while the kettle is ‘on’ as doing so would lead to a
negtive power position.
2.2 Code Justification Requirements
The mark for ‘code justification’ are approximately equally divided for the justification types shown in
column 3. Deductions proportional deductions will be made if criteria in column 2 are not met when
meeting functional requirements (section 2.1). The code alone will not receive marks for this section.
Concept Code must implement… At each implemented location, the code
comments must explain and justify why it is
more suitable to…
Classes Multiple classes. Each class must be
in its own file. Must follow naming
conventions shown in lectures. All
code must be formatted using
Comments must start on a new line,
before the code being commented (do
not include in-line comments). There
must be no unreachable code. If a
class has a red dot, it will result in 0
marks for the entire submission.
… use the name given for your class over other
names that may be somewhat acceptable.
… keep the composition of your class that way
instead of splitting it further (to create more
classes) or merging it with another (and
reducing the overall number of classes).
Each class must only have private
object member variables (and/or
arrays) that are not static. Only
declarations should be at class level
(There should be no = signs near
declaration). Names of these must be
descriptive of their contents and must
follow naming conventions shown in
… name this member variable that way instead
of using other potentially suitable names.
… use this data type chosen instead of other
compatible data types.
… declare this variable as a member of the
whole object as opposed to having it declared
inside a method or several methods.
Constructors Each class must have one constructor
and it must be public. Constructor
must have corresponding parameters
for the most important object member
variables declared in that class and
assign them. The constructor must
ensure that it initialises all member
variables before doing anything else.
… use your choice of constructor parameters
(which maybe none) over other potentially
… perform only what you have performed in
the rest of the constructor (excluding
parameter declarations and initialiations).
Methods must be explicitly public
and not static. Method names must
describe actions and must follow
method naming conventions shown in
lectures. Methods may take
parameters and/or return values. A
method can only have one ‘return’
statement at most and this must be the
very last statement in the method (no
… use the name given for your method over
other names that may be somewhat acceptable.
… use your choice of parameters (which
maybe none) over other potentially suitable
… use your choice of return type (or void)
over other potentially suitable choices.
… keep the composition of your method that
way instead of splitting it further (to create
spaghetti code). All references to
member variables and/or arrays from
methods must begin with “this.”.
Only one class must have the ‘public
static void main…’ method and it
must only create an object of the class
in which it is contained (this would
start the application).
more methods) or merging it with another (and
reducing the number of methods).
Arrays The program must use standard Java
array concepts to maintain added
devices and the data type of the array
must be of a class type that you have
created (you need the array in
addition to the any GTerm list that
might hold the same data). The array
may have a maximum capacity but
the program must work any number
of devices added. Must only use
concepts covered in lectures (e.g. do
not use Array, Arrays, ArrayList, etc.
… name the array that way instead of using
other potentially suitable names.
… use the data type chosen instead of other
compatible data types.
… declare the array as an object
member/inside a method as opposed to
declaring it inside a method/as an object
本网站支持淘宝 支付宝 微信支付 paypal等等交易。如果不放心可以用淘宝交易！
E-mail: [email protected] 微信:itcsdx