Lab 09 Solution

$35.00 $29.05

You'll get a: . zip file solution, download link after Payment

Category: Tag:


* Implement a class given a contract.

* Gain experience with Java generics.


An individual repository for this lab has been created for you here (replace z5555555 with your own zID):


This lab will be entirely automarked. Some tests have been provided, but the tests used for automarking will be more exhaustive. Partial marks are available (see below). It’s important that you carefully read through the specification and the provided code to ensure you have a complete understanding of what is required.

In addition to being worth lab marks, this exercise is also similar in style to a question you will need to answer in the exam, so it is good practice. That question will also be entirely automarked.


In the provided code, the `unsw.collections.Set` interface represents a generic set. Note that this is different to the standard `java.util.Set`. Also provided is a partially complete implementation of this interface in `unsw.collections.ArrayListSet`. In addition to implementing the interface methods, this class also needs to implement the `iterator()` method from `Iterable` and the `equals(…)` method. Your task is to complete it without making any changes to the `Set` interface and ensuring it is consistent with the documentation and contract (including the invariant in `ArrayListSet`).

What follows is a list of the methods that need to be implemented, in rough order of difficulty with the corresponding mark weighting.

* `add(…)` – *0.5 marks*

* `subsetOf(…)` – *0.25 marks*

* `iterator()` – *0.25 marks*

* `union(…)` – *0.25 marks*

* `intersection(…)` – *0.25 marks*

* `equals(…)` – *1 mark*

Note that the automarking for all tests will assume the `add(..)`, `remove(…)`, `contains(…)`, and `size()` work. Because you are implementing `add(…)` yourselves, it will need to be correct for you to get any marks. You shouldn’t need to change `remove(…)`, `contains(…)`, and `size()`.


* The `iterator()` method can be implemented in one line.

* For `equals(…)`, you will need to use `instanceof` and wildcards (`?`) in the body of the method.

* Some basic tests have been given, but you will need to write some of your own to check correctness.


Make sure that all your work has been pushed to GitLab then submit it with:


$ 2511 submit lab09