Logistics
You have 40 minutes to complete this exam. All exams must be completely submitted by the end of this 50 minute period.
Exam Overview
A farm and retail outlet is using aLinkedList
-basedTreeInventory
to keep track of theirTree
s.They have several lots of
Tree
s. The inventory of each is kept in a different datafile. You do not need to know the format of this file, because it is parsed and read for you. But, because it might be helpful for debugging, we have included a description below in the Datafiles section of this document.The owner of the tree farm and retail outlet keeps a sorted list of
Tree
s byheight
for each lot, from the smallest to the largest. This helps him to locate trees that are the right size for his customers.He wants to cull some trees from one of his lots and has chosen to remove those that can be found on another lot. The trees in each lot have heights that are unique (i.e., there are no duplicate elements in any list).
Fortunately, the
TreeInventory
program does exactly this. It reads the two specified sorted datafiles, one for each lot, and produces a list of theTree
s sorted from the shortest to the tallest. Instructions for its use are provided in the running the program section below.This feature of the
TreeInventory
program relies on the following unimplemented method of theLinkedList
class:void removeItems(LinkedList otherList)
It is your job to implement this method. This is the only method you are required to implement. Its behavior is described in the removeItems(LinkedList otherList) section below. You may implement private helper methods within the
LinkedList
class, if you choose.You may not otherwise alter any of the files you have been provided.
removeItems(LinkedList otherList)
This method of theLinkedList
class is unimplemented. You should implement it.It should remove the
Node
s in theLinkedList
that have data items matching the ones inotherList
using thecompareTo()
method of its data items. When finished, the remaining items in the original list must remain in order sorted from smallest value to largest. Also, the items in otherList must be unchanged. We have already implementedcompareTo()
for you. It will properly compare twoTree
s based on theirheightInInches
.No list contains any duplicate items.
Running The Program
To run the program, execute theTreeInventory
class, providing the two datafiles as parameters, including the path, if necessary.For example
java TreeInventory ../datafiles/lot3.dat ../datafiles/lot2.datwill use your
removeItems(LinkedList otherList)
method to produce a listing of allTree
s contained in "lot3.dat" that are not in "lot2.dat", in sorted order by theirheightInInches
.
The Datafiles
Sample datafiles are contained within the "datafiles" subdirectory. Each data file contains one line perTree
. EachTree
is described by itsheightInFeet
, itspriceInDollarsAndCents
, and itsqualityFrom1Through10
.So, each line of the datafile contains three numbers, as shown below:
heightInFeet priceInDollarsAndCents qualityFrom1Through10
heightInFeet
is anint
priceInDollarsAndCents
is adouble
qualityFrom1Through10
is anint
For example, the datafile, "lot3.dat" reads as follows:
20 5000.00 8 6 75.00 10 3 10.00 1
- The first tree is 20 feet tall, costs $5000, and is an 8 on the scale of 1 - 10 (very good).
- The second tree is 6 feet tall, costs $75, and is a "perfect 10".
- The second tree is 3 feet tall, costs $10, and is best suited for firewood, with the lowest quality rating of "1".
You might be surprised that the datafile is sorted in the opposite order -- from tallest to shortest. Please don't worry about this, when the
LinkedList
is created, the order is reversed.
Download This: Everythng You Need
Exam.zip contains everything you need:
- This document
- JavaDoc for all of the classes
- The source code for all classes and skeletons
- The datafiles we will use for testing.
- The
.class files from the reference solution.