Lab 3

Code for this lab

This lab uses a different driver than the other lab, so go ahead an pull this code and put it into Eclipse like you did last time

When you first open up this lab the first thing you will see is that it has errors! The driver has a few errors in it, but don't worry about those. They will be gone by the time we are finished.

The goal of this lab is to begin the idea of searching through sets. You went over this in class so I won't go into this.

We will only be editing the FlatFile.java and Record.java classes in this lab. We will also be creating a new class called Key.

Let's start with the easy part and create the Key class. Once you make it we only need one method in it. We will make a method called getKey that takes a Record as a parameter and returns the Records name. (This method needs to be public, but also something else, see if you can figure it out)

Next! Time to go ahead and edit the Record class because that's pretty easy too. We just need to make a getKey method in this class. Since we aren't adding a Key to the record object we will be calling the method directly from the Key class (Key.getKey). That should give you a hint about how to set up the method in Key. Once you have that set up we can move on to the FlatFile

Now things will get a bit more difficult. First we will change the findName method to findRecordWithKey. This was a change made in the driver so we will go ahead and do that. I changed the parameter name as well, but it's not that important, just makes it easier to follow since we are using "keys" now instead of strings.

Now we should change the getName methods inside of the findRecordWithKey method to getKey. This is so when we begin to build on our key class later we have it already set up. Right now it is just redirecting you to the name, but it will do more later.

Last thing to change. If we save everything there should only be one error left in the driver. We need to change the readFile method to take another parameter (an int). You can look at the Driver to see the order and such. The point of that parameter is to tell you how many we are going to have, so in the readFile we will change the while loop to a for loop, going from 0->the new param

If everything is done it should work now! Run it and compare zlogfileold with zlogfile

Zip up the folder and submit to dropbox!