Java Question COMP 1020
Java Question COMP 1020
Question 1: Linked Lists
Create a PersonLinkedList class to hold a linked list whose values are of type Person (use the Person.java file provided
in the Assignment 4 folder). You will also have to implement a PersonNode class to represent nodes in the linked list.
Your linked list must implement the methods below. For full marks, your methods should be efficient in that they should
not do any unnecessary extra traversals through the list.
A constructor with no parameters which creates an empty list.
public void insertByAge(Person newItem) – the insert method should add the Person object to the
list such hat the list is ordered according to age (youngest to oldest)
public int size() which returns the number of elements in the linked list
public boolean contains(Person person) which returns true if the list contains the data item and
false otherwise.
public Person get(int pos) which returns the Person object at the given position in the list (where the
position of the first item in the list is 0, the position of the second item is 1, etc). If there is no such position in
the list, the method should return null.
public double getAverageAge() which computes and returns the average (mean) age of the people in
the list. The method should return 0.0 if the list is empty.
Public boolean equals(PersonLinkedList otherList) which will return true if the list contains
identical Person information in the same order.
public PersonLinkedList removeIfYounger(int age) – this method should remove all Person
objects from the list who are younger than the age passed as a parameter. The removed items should then
DETAILED ASSIGNMENT