0% found this document useful (0 votes)
8 views3 pages

Homework 2 Assignment Brief

Uploaded by

dongodaara1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Homework 2 Assignment Brief

Uploaded by

dongodaara1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming 1

Individual Assessed Coursework 2


October 2024

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.

Step 2: adding functionality to the App class.


For this step, you should
 write a method download() which allows a user to "download the exercise app". Since this
is only a model, all we do is output appropriate information. 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.

Title: Step Counter App


Objective: To get fitter
Download cost: 75

It also updates the value of a new field numberOfDownloads.


 add two fields which
o store the name of the player with the highest step count called
highestStepCountName;
o store the step count itself called highestStepCount.
 write a method checkStepCount() which, when given a person's step count and name in
that order, checks to see whether that particular step count is the highest step count to date
and if so, replaces the highest step count with this new step count and also replaces the
relevant highest step count name.

-1- Wednesday, 06 November 2024


Programming 1

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

Title: Step Counter App


Objective: To get fitter
Download cost: 75
Number of downloads to date: 4539
Highest step count to date: 15000
Player with highest step count: Laura M

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.

Title: Step Counter App


Objective: To get fitter
Download cost: 75
Number of downloads to date: 4539
Highest step count to date: 15000
Player with highest step count: Laura M
Earnings to date: 87454

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.

-2- Wednesday, 06 November 2024


Programming 1

To test your code


 create a Controller object;
 create an App object, and pass to its constructor
o values for the three fields (as usual);
o the identifier for the Controller object e.g. controller1 (or, more easily, click
on the Controller object on the Object Bench);
 inspect the App object using the Object Inspector. If you double click on the
appController field, a new Object Inspector window will open and you should see the
fields of the Controller object you created -- this will confirm that your code for Step 4 is
working correctly.

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

Title: Step Counter App


Objective: To get fitter
Download cost: 75
Number of downloads to date: 4539
Highest step count to date: 15000
Player with highest step count: Laura M
Earnings to date: 87454
Controller’s name: Jones

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.

-3- Wednesday, 06 November 2024

You might also like