CSC220 Lab Number 3
Due: 10:59AM, Tuesday, September 21
This lab consists of three parts.
Part 1
Download the following file:
The task is to implement missing methods in KWLinkedList.java.
They are:
- public void addFirst(E item),
which inserts the item item given as an argument
as the first element.
- public void addLast(E item),
which inserts the item item given as an argument
as the last element.
- public E getFirst(),
which returns the first element.
- public E getLast(),
which returns the last element.
- public Iterator < E > iterator(),
which returns the iterator object.
- public ListIterator < E > listIterator(),
which returns the listiterator object.
- public ListIterator < E > listIterator(int index),
which returns the listiterator object starting from the element
at index index.
- Methods remove , which removes the item referenced to
by lastItemReturned. This requires modifications of
the next and prev values flanking the item.
indexed by the and set , also, head or tail
when one of these is removed.
- Methods set, which changes the data of
lastItemReturned.
Part 2
Download the following files:
The Router class object consists of three data fields:
- name, which is a String object,
- startupCost, which is a nonnegative double object, and
- communicationCost, which is a nonnegative double object.
Necessary operations for creating and accessing a Router class object
are defined in this java file.
Suppose we are maintaining a KWLinkedList of Router class objects,
no two names are identical.
A data of the list can be read from a file that has in each line
has a Router class object description, where the three data fields
are written in plain text with a common as a separator, such as
"Mitsu:10.0:9.0". router-data.txt is a sample fle.
Your task is to write a class named, RouterList.java, whose data field
is a KWLinkedList of Router class objects, and has a method that
reads data from such a file, where the file is specified using JFileChooser.
Part 3
Write a method for the class RouterList.java code
that takes as input two String objects, NAME1 and NAME2,
and compute, if both String objects appear as names of Router class objects
on the list, a double value V, defined as follows:
- If NAME1 is identical to NAME2, then
V is the startupCost associated with NAME1
- If NAME1 is not identical to NAME2, then
V is the startupCost associated with NAME1
plus the communicationCost associated with NAME1
plus the sum of the communicationCost associated with all the Router
class objects between the objects associated with NAME1 and with NAME2.
Note that NAME2 may come after or before NAME1.
If either NAME1 or NAME2 doesn't appear on the list, then V is -1.0.
For example, the value V for (Mitsu, Bill) is 100.0+10.0+9.0 = 119.0
while the value V for (Bill, Mitsu) is 80.0+8.0+9.0=97.0