ITI1121 Final Exam solution

$24.99

Original Work ?
Category: You will Instantly receive a download link for .ZIP solution file upon Payment

Description

5/5 - (3 votes)

Question 1
File to submit: Q1.java
The only file you can change is Q1.java. In Q1.java, complete the method manageLength. It takes a linkedList
of elements of type Client, and an int “length” as parameters. It should use an iterator to iterate through the
elements of the list, and complete the following:
– If a client has a value of the instance variable relationshipLength that is greater than the parameter
“length”: then it will add one star (1) to the instance variable “stars” of this client.
– If a client has more than 5 stars (regardless of whether the star was newly added or had 5 from before)
then this client will be added to a new list called VIPClients. The clients will be added to VIPClients list
in the same order they are in clientList. See example below.
At the end of the method manageLength, return the list VIPClients. This list may be empty. You should return it
even if it is empty.
Hint: The class Client contains all the setters and getters needed to complete this program.
A file to test your work has been provided: UseQ1.java. You cannot change it in any way. You code will be
tested with the file as provided to you.
Run it to make sure your work is successful. The result should be exactly as follows:
**************** START TEST 1 *****************
Original list: [1*Client1*2*1 | 2*Client2*8*10 | 3*Client3*7*5 | 4*Client4*4*4]
Modified list: [1*Client1*2*1 | 2*Client2*8*11 | 3*Client3*7*6 | 4*Client4*4*4]
VIP List : [2*Client2*8*11 | 3*Client3*7*6]
***********************************************
**************** START TEST 2 *****************
Original list: [1*Client1*2*5 | 2*Client2*0*5 | 3*Client3*7*5 | 4*Client4*4*5]
Modified list: [1*Client1*2*5 | 2*Client2*0*5 | 3*Client3*7*5 | 4*Client4*4*5]
VIP List : [1*Client1*2*5 | 2*Client2*0*5 | 3*Client3*7*5 | 4*Client4*4*5]
***********************************************
**************** START TEST 3 *****************
Original list: [1*Client1*3*1 | 2*Client2*7*2 | 3*Client3*2*3 | 4*Client4*9*4]
Modified list: [1*Client1*3*2 | 2*Client2*7*3 | 3*Client3*2*4 | 4*Client4*9*5]
VIP List : [4*Client4*9*5]
***********************************************
Question 2 (4 points)
File to submit: Q2LinkedList.java
You are provided with the template Q2LinkedList.java which is an implementation of a Doubly linked list with
a Dummy node.
You need to complete the method eliminateValues(E certainValue) to eliminate any element of value equal to
certainValue, which passed to the method as parameter. Remove all the elements that have the value
certainValue. (Make sure your program doesn’t remove the head of the list.)
Do Not make a call to any other method(s) in eliminateValues(). Do Not implement any other method and do
not call any of the existing methods in Q2LinkedList.java. The method eliminateValues needs to complete the
task of removing “certainValue” independently without any method call. This means you will use the operator
.next and/or .prev directly to complete this program.
You cannot change anything already existing in the class Q2LinkedList.java.
The provided Q2linkedList implementation does not provide a size. You cannot add a size to the
implementation. You need to complete this program without using the list size.
A test file has been provided UseQ2LinkedList.java which tests your implementation using a LinkedList of
Strings. Do not change it.
Make sure to test your code using UseQ2LinkedList.java , a successful result should look like this:
====================================================
————- Test 1 – Eliminate:”” ————-
Q2LinkedList: | fox | ant | dog | | bat | cat |
Q2LinkedList: | fox | ant | dog | bat | cat |
====================================================
————- Test 2 Eliminate:”bla” ————-
Q2LinkedList: | ant | dog | bat | bla | cat | bla |
Q2LinkedList: | ant | dog | bat | cat |
====================================================
————- Test 3 Eliminate:” here” ————-
Q2LinkedList: | here | dog | bat | here | cat | here |
Q2LinkedList: | dog | bat | cat |
====================================================
Question 3
File to submit: Q3LinkedList.java
Q3LinkedList implements a singly linked list. This list contains negative and positive integers. You can assume
it does not contain any zeros.
All the negative elements in the list are before the positive elements. See the examples below.
Complete the method insertValue(E valuetoInsert) so that the parameter “valuetoInsert” is inserted in the list
after all the existing negative elements and before any existing positive element.
The only method you can implement is the method insertValue. And the only method you can call within
insertValue is the method isNegative() provided. Do Not make a call to any other method.
You can assume there will be at least one negative element in the list. This means you will Not need to insert
“valuetoInsert” passed in parameter as first element in the list.
You should test your program using UseQ3LinkedList.java. The successful output should be exactly as below:
****************************************************
———————— Test 1 ——————–
——– one negative element, rest positive: ——-
[-5, 8, 10, 9]
[-5, 100, 8, 10, 9]
****************************************************
———————— Test 2 ——————–
——————few negative elements————–
[-8, -10, -9, 5]
[-8, -10, -9, 100, 5]
****************************************************
———————— Test 3 ——————–
——————-all negative elements————-
[-5, -8, -10, -9]
[-5, -8, -10, -9, 100]
****************************************************