This goal of this exercise is to demonstrate how difficult complete correctness is, even on reasonably simply tasks. This may be a humbling exercise, but we hope not a discouraging one.
Secondary goals include getting your mind back into Java programming and getting used to the workflow of projects in this course.
You will be asked to do a series of problems exercising mostly Programming I material. They will be tested using given JUnit tests. Conventional wisdom is that even professional programmers have difficulty getting perfect solutions (covering all corner cases) to problems like these when put under time pressure. Also tasks like this aren't uncommon in job interviews. Let's see how you do.
Note that unlike other projects, you must submit your solution to this project by Friday, Jan 17.
For most other projects, the project description found on the course website is short, directing you to the project as descriped in the book. I've made this one a full description to help you start the semester and also to provide some guidance on setting up projects, but this is largely redundant with Project 1.1 in the book, pg 11. For more help on setting up projects and some practical tips, see the project guide for this course.
The projects are based on starter code found in the
public folder for this course, ~tvandrun/Public/cs345
.
There are certain critical parts of the code for you to finish.
The code is accompanied with JUnit test cases you are to use
to test your solution.
The instructions here lead you through setting up a project
in Eclipse on the lab machines, which I recommend.
Make a folder and copy the starter code from the course folder something like this:
mkdir cs345 cd cs345 mkdir projects cd projects cp -r ~tvandrun/Public/cs345/pretest .
(You should know how to do that by now, but just to get you started on the exercise faster.)
Open Eclipse.
I recommend you make a new workspace for this course,
perhaps with the path cs345/projects/workspace
.
Start a new Java project.
Uncheck "Use default location" and instead select as a location
the folder that you copied from the course folder.
Hit "Next>" and confirm that you see something like this:
Hit "Finish".
In the next screen, in the Package Explorer tab,
expand "tests" to see BinSearchTest
and several versions of LinkedListTest
.
Right-click on BinSearchTest
and
select "Run as -> JUnit test".
If you see something like the following, then you're all set up.
Open Exercise1.java
.
Your task is to implement binary search.
The method stub takes a sorted array array
of some type generic T
that implements
Comparable
and a specific item
of that type.
Recall that the Comparable
interface has a method
compareTo()
that can be used like
x.compareTo(y)
...and it will return a negative number if x is "less than" y, a positive number if y is "less than" x, and 0 if x and y are "equal". Some details:
Test your implementation using BinSearchTest
.
JUnit will give
you a failure message indicating something of what is wrong.
Mainly you need to think about your code.
When you pass all the tests, move on.
Open Exercise2.java
.
Your task is to implement certain operations in a linked list class.
Read the documentation and code through the add()
method
to get a feel for how this linked list works.
Run the JUnit test LinkedListTestA
.
Out of the box the following tests should pass:
emptySize
, oneSize
,
emptyIterator
, fillIterator
,
fullSize
, and oneIterator
.
The rest should fail.
Write the get()
method according to the
specification given in the documentation.
Test by rerunning the JUnit test.
If you write this correctly, LinkedListTestA
should
all pass.
Again, you don't waste time looking at the source code for the tests. The error messages (as well as the names of the tests), should give some hints about what's wrong if they fail. When they all pass, try the next one.
Write the set()
method according to the
specificiation given in the documentation.
This should be very similar to get()
, right?
You may overwrite the datum of an existing node---you do not need
to make a new node.
Test this using LinkedListTestB
, which
will also run all the tests of LinkedListTestA
,
which it inherits.
Everything we've done so far is "easy";
the difficulty comes only with the time pressure.
But now see if you can push it even further with a problem
that has some challenge to it.
Implement the remove()
method of the
Exercise2
class
(not the
remove()
method of the iterator),
according to the speficiation given in the documentation.
Test this using LinkedListTestC
(which inherits all the tests from the two previous steps).
Let's see some green bars.
There also exists an Exercise3
class for
an exericse in which you are to implement selection sort.
This is recommended for your own practice, but you do
not need to turn it in.
Please copy the Java files you modified your files to your turn-in folder:
cp exercises/Exercise1.java /cslab/class/cs345/(your id)/pretest cp exercises/Exercise2.java /cslab/class/cs345/(your id)/pretest
To keep up with this course, this should be finished by Jan 15. The absolute deadline for this is Jan 17.