Homework 2 Assignment Brief
Homework 2 Assignment Brief
This homework is designed to give you more practice with accessor and mutator methods; with
passing parameters to methods; and with using basic objects. The initial class that you will write
models an exercise App which records that person’s step count and other features.
We expect that you will already have completed the exercises in Worksheet One and Worksheet
Two on the Bank project and the Account class that are described there and as such already have a
good base of knowledge to use for this homework. If you have not already completed these
exercises then you must first carefully work through them.
For this homework, you must use the names of fields (and all other variables
and methods) as they are exactly specified in this document.
Noting also for method names that if you have a variable called
numberOfOwners, then a mutator for this field is called setNumberOfOwners
and the corresponding accessor is called getNumberOfOwners.
Step 1
The basic App class should have
three fields, title, objective (of the app) and costInPence (in pence of each
download);
a constructor, which allows you to pass arguments to initialise these three attributes in the
order specified above;
accessor and mutator methods for each field.
write a printReport() method which outputs the title, the objective of the app, the cost of
each download, the number of downloads, the highest step count and the name of the person
who has that step count. Each piece of information must be printed on a separate line AND
in the order given below AND using the exact text shown below at the start of each line. The
values of each appropriate field then follow that text as in this example.
Step 3
So far, testing of the program has been quite repetitive and always starts from scratch. However, we
could introduce a default constructor with the field values hard-coded. This means that when we
create our object and then call this default constructor, the field values are automatically inserted
into each field. This will help particularly with your testing. So, introduce a second, default
constructor now.
Then
write a method calculateEarnings() which calculates how much money this particular
app has earnt its writer;
o do not add an extra field to keep track of the running earnings total.
Now amend your printReport() method to include this new information i.e. the earnings
to date, on a separate last line exactly in the manner below.
Note that any number printed above should be simply output as a whole number without any
additional symbols or formatting.
Step 4
Introduce a new class, called Controller, to the project. Its purpose is to represent the controller
of the app. It should have
two fields surname and controllerID (where the latter is a mix of numbers and letters);
a suitable constructor with parameters for only these two fields in the order specified above
as well as appropriate accessor methods.
Next add a new field appController, of type Controller, to the App class. Modify App’s
constructor by giving it an additional last parameter so that the new field can be initialised when
the constructor is called.
Now amend the printReport()method of the App class so that it also outputs the surname of the
manager on a separate last line exactly in the manner below
Hand in details
You should upload two files: App.java & Controller.java to separate upload areas (details to
follow) by 16.00 on Thursday 31st October.
Note that by the act of following these instructions and handing your work in, it is deemed
that you have read and understand the rules on plagiarism as written in your student
handbook.