COMP3200 Assignment 3
Copyright David J. Barnes
Date of this version: 2021.12.14
This assignment is designed to give you further practice with the core elements of the
course. In particular, you will need to make extensive use of the Java API documentation
and collection classes. The task involves a significant amount of programming in order to
ensure that you are ready for further programming tasks in future modules.
Date set: Tue 7th December 2021
Deadline: 23:55 Mon 17th January 2022
Weighting: 15% of the module’s coursework mark.
You will hand the assignment in on Moodle in the Assignment 3 Upload Area within the
Download the starting project from:
Please make an effort to read through the assignment as soon as possible so that you know
what you need to understand to complete it, and can think about how best to organise your
time. Research has found that, “When students received A- and B-level scores, they started
earlier and finished earlier than on assignments where they received lower scores [but] they
did not appear to spend any more time on their work.” (Stephen H. Edwards, et al.,
Comparing Effective and Ineffective Behaviors of Student Programmers.)
Plagiarism and Duplication of Material
The work you submit must be your own. We will run checks on all submitted work in an
effort to identify possible plagiarism, and take disciplinary action against anyone found to
have committed plagiarism. You are also reminded that seeking assistance from external
‘homework’ sites is not permitted and might constitute ‘contract cheating’ which is
forbidden by the University.
Some guidelines on avoiding plagiarism:
• One of the most common reasons for programming plagiarism is leaving work until
the last minute. Avoid this by making sure that you know what you have to do (that
is not necessarily the same as how to do it) as soon as an assessment is set. Then
decide what you will need to do in order to complete the assignment. This will
typically involve doing some background reading and programming practice. If in
doubt about what is required, ask a member of the course team.
• Another common reason is working too closely with one or more other students on
the course. Do not program together with someone else, by which I mean do not
work together at a single PC, or side by side, typing in more or less the same code. By
all means discuss parts of an assignment, but do not thereby end up submitting the
• It is not acceptable to submit code that differs only in the comments and variable
names, for instance. It is very easy for us to detect when this has been done and we
will check for it.
• Never let someone else have a copy of your code, no matter how desperate they
are. Always advise someone in this position to seek help from their class supervisor
or lecturer. Otherwise, they will never properly learn for themselves.
• It is not acceptable to post assignments on sites such as Chegg, Freelancer, etc. and
we treat such actions as evidence of attempted plagiarism, regardless of whether or
not work is paid for.
Further advice on plagiarism and collaboration is also available.
You are reminded of the rules about plagiarism that can be found in the Stage I Handbook.
These rules apply to programming assignments. We reserve the right to apply checks to
programs submitted for assignment in order to guard against plagiarism and to use
programs submitted to test and refine our plagiarism detection methods both during the
course and in the future.
Santa needs new software for his Sleigh Delivery System (SDS) but the elves who were
working on it have been seconded to help out with a different project somewhere in
Lapland, so he needs you to complete it for him.
He hopes the software will help him deliver presents in an efficient way. The system keeps
an inventory of which addresses he has to deliver presents to and how many presents are
going to each address. Because his sleigh has a finite capacity, he will sometimes have to
make multiple trips to the same area. Santa tends to plan his deliveries based on postcode
areas and that is reflected in the functionality you need to implement.
There is already an Address class written and you must not change it in any way. Instances
of this class record the post code and house number to which packages are to be delivered.
Note that a postcode is usually associated with multiple house numbers in the same area
There are two classes that the elves did not complete before they left: Inventory and
Scheduler. They wrote the method headers and associated bodies most of the functionality
is missing. There is also a Main class that creates some randomised data to help with testing
The Inventory class keeps track of how many presents have to be delivered to each Address.
Note that, presents for a particular address might arrive at his North Pole headquarters at
different times, so the number of presents for each address keep on having to be updated.
The Inventory class also requires methods to be completed that allow Santa to look up
information based on addresses and postcodes.
The Scheduler class has only two methods: one that allows Santa to work out how many
trips he will have to make to and from the North Pole, and the other to work out his
preferred order of visiting houses.
Your task is to complete the Inventory and Scheduler classes to fit the requirements given
below. You must not change any of the method heads in Inventory and Scheduler but you
may add additional private methods if you wish. You may edit the Main class in whatever
way you wish as it will not be assessed.
Complete the following methods of the Inventory and Scheduler classes to fit the given
• Inventory: addToInventory. This method receives an address and a number of
presents for that address. There may be multiple calls to this method with the same
address. The inventory must keep track of the total number of presents associated
with each address.
• Inventory: presentsForAddress. This method must return the total number of
presents to be delivered to the given address.
• Inventory: presentsForPostcode: Multiple addresses may share the same postcode
but have different house numbers. This method must return the total number of
presents to be delivered to all the houses with the given postcode.
• Inventory: addressesForPostcodePrefix: Multiple addresses may share the same 4-
character postcode prefix; for instance: WT86 6ET, WT86 1XN and WT86 3RH.
This method must return the list of addresses to be delivered to with the given
postcode prefix (e.g., WT86).
Clarification: this method must not assume that the parameter will always be 4-
characters long. It is simply a String that might be the prefix of one or more full
postcodes. For instance, the prefix WT is a prefix of all postcodes that start with WT
and the prefix WT86 6ET is a prefix of the full postcode WT86 6ET.
• Scheduler: numberOfTrips: Santa’s sleigh can only hold a limited number of
packages. So, he will have to make multiple trips to a particular postcode area if
more presents have to be delivered there than will fit on the sleigh. This method
must calculate how many trips he will have to make, assuming he is able to
completely fill the sleigh (if necessary) on a single trip. For instance, if his sleigh can
hold 10 packages and he has 3 to deliver then that will require 1 trip, but 11
packages would require 2 trips.
The number of presents it can hold is defined by the value of the class variable
PACKAGES_PER_SLEIGH in the Scheduler class. You must not change the value of this
variable but please note that a different value will be used for it during the marking
of the assessment.
• Scheduler: deliveryOrder. Challenging. Note that this method is significantly more
challenging to implement than the others.
Santa delivers presents to a single postcode by visiting the odd-numbered houses
first – in ascending order of house number – and then the even-numbered houses in
descending order. For instance: 3, 7, 13, 16, 12, 4, 2. This method must return the list
of integer house numbers using that ordering for delivery to the given postcode in
The Main class and main method
The Main class has been provided as an example of the way in which sample data could be
generated and the required methods called. You may modify this class in whatever way you
wish as it will not form part of the assessment. The sample output below shows the results
of calling some of the required methods on some randomly generated data.
Postcode: WT86 3RH
Number of presents to the postcode: 18
Number of sleds required for the postcode: 1
Number of presents for address: 17 WT86 3RH is 2
Delivery order to the postcode: [17, 29, 44, 26]
Address list for prefix WT86 is:[19 WT86 6ET, …, 5 WT86 3EJ]
A note on postcodes
The space often written between the two parts of UK postcodes is optional and makes no
difference to its interpretation. For instance, "WT86 6ET" and "WT866ET" are
unambiguously the same postcode. However, your code will not be tested with some
postcodes that have spaces and some that do not. All will either have a space or none will.
If you need help with the assignment, there are various places you can go. You will not lose
marks if you ask for help.
• You can ask questions on the module’s anonymous Q&A page and it is ok to post
code there because I will edit it before publishing.
• You can ask the module’s lecturer.
Be very careful about asking for help from other students on the course, or students who
have taken the course before, other than as described above. If in doubt about what is
appropriate, check the plagiarism guidelines above and/or ask the module’s lecturer.
Before you submit your assessment, thoroughly test the whole class to make sure that
nothing you added later has broken anything added earlier. If you are unable to complete
the class – even if you cannot get it to compile – still submit what you have done because it
is likely that you will get at least some credit for it.
David Barnes, 2021.12.07: with acknowledgement for its inspiration to Eric Wastl and
Advent of Code (https://adventofcode.com/)
Changes to the original version
2021.12.08: Corrected the description of what is to be returned from
addressesForPostcodePrefix: a list not an integer.
2021.12.13: A section with a note on postcodes added.
2021.12.14: Clarification added to the addressesForPostcodePrefix method for the meaning