Logistics
You have 40 minutes to complete this exam. All exams must be completely submitted by the end of this 50 minute period.To submit your exam solution, please place a government-issued or University-issued photo-ID on the table in front of you so that it is readily visible, then raise your hand to summon a proctor. The proctor will then verify your identity, and enter the password allowing your to submit your file.
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 wants a sorted list of
Tree
s bypriceInDollarsAndCents
, from the lowest price to the highest price, in order that he can bring customers directly to the best buys, and serve more customers in less time with less time-wasting browsing.Fortunately, the
TreeInventory
program does exactly this. It reads a specified datafile and produces a list of theTree
s sorted by price as prescribed above. 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 sort()
It is your job to implement this method. This is the only method you are required to implement. It's behavior is described in the sort() 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.
sort()
This method of theLinkedList
class is unimplemented. You should implement it.It should sort the
LinkedList
using thecompareTo()
method of its data items so that the items are stored from the lowest value to the highest value. In this case, the data items areTree
s, and we have already implementedcompareTo()
for you. It will properly compare twoTree
s based onpriceInDollarsAndCents
.As a result, you simply need to implement the generic
sort()
method within theLinkedList
class.
Running The Program
To run the program, execute theTreeInventory
class, providing the datafile as a parameter, including the path, if necessary.For example
java TreeInventory ../datafiles/lot3.datwill use your
sort()
method to produce a listing of allTree
s contained within the "lot3.dat" sorted by their "priceInDollarsAndCents".
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:
6 75.00 10 3 10.00 1 20 5000.00 8
- The first 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".
- The third tree is 20 feet tall, costs $5000, and is an 8 on the scale of 1 - 10 (very good).
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.