11:59.59pm, Sunday, March 9
NOTE: I'm still waiting on the college for
more/better directory information. You'll probably want to put off working
on the application section until lab time as there may be some last minute
changes.
I've not heard back from the college, so go ahead with the data as-is.
NOTE: We're working on a way to easily share files between you and your partner. It should be working by the end of Monday, so during lab today, just use one person's account and look for an update in this space.
This week we are going to implementing a doubly linked list and using it to run an email directory application. You'll also implement your first "real" iterator and can use it in your project.
The directory information that I'm supplying has been culled from a number of campus sources, but should not be made available to anyone outside this class. This includes posting it on web sites.
You may work with a partner on this assignment. I know that this means that some groups will have 2 people working on pieces individually instead of as a group. I'd like it if you initially sit down together and discuss the design of the overall program before splitting up the work instead of just trying to meld the two pieces together at the end.
Since I don't want the data files distributed outside the class, you'll need to copy the jar file from a lab machine instead of downloading it.
cp ~kuperman/pub/cs151/lab4.jar .
You'll be creating a doubly linked list called MyLinkedList and an iterator for that class.
This is just a subset of LinkedList and should have the same behavior for the methods you write.
You should extend AbstractList and implement the Iterable interface.
Be sure to test your implementation thoroughly. In doubly linked lists, the removal of items can be especially tricky as you need to be sure to properly update the neighbor's next and previous pointers, as well as handling the special cases for removal from the front or tail.
We will not be permitting "null" pointers to be inserted into the list. You should throw a NullPointerException if someone attempts to do so.
You only need a 0-argument constructor that creates an empty list.
Create a getNth() method that returns the node at a specified index, not the content.
These are methods that weren't in MyArrayList, but might be useful in a LinkedList.
There is a skeleton of an iterator factory method included in the file. You need to implement hasNext and next in order to make it work.
You'll probably want to create a nested class to represent a node in your linked list. Remember that to do this, you can't declare the class as public. Also, since you'll need to be modifying these nodes, you might want to consider creating private methods that return a reference to a node instead of the data inside the node.
You should be able to re-use the tests you wrote in Lab 1 for MyArrayList. Just make changes similar to
List<String> x = new MyLinkedList<String>();
For this part of the project, I want you to create a directory application that will let you have a personal list of email addresses as well as the ability to query the whole student directory.
You first are going to create a class that can hold an entry and has methods that make it useful for searching. The fields that must be supported are:
And you may add to these if you want. However, for the equals() method, these are the only fields that matter.
NOTE: for your own sanity, you should not permit any field to contain the ':' character. Check for them and either drop them, transform them into a valid character, or truncate the string at that point. Similarly, you should check that the user doesn't input any '%' characters in inputs other than those for searching
For the equals() method, I want you to apply the following rules:
Matches must be made in case-insensitive fashion. However, the case that is displayed to the user must allow for mixed case.
"Benjamin" matches "BeNjAmIn" but prints differently
"Ben" doesn't match "Benjamin"
"Ben%" matches "Benjamin"
Now create a class Directory.java that will act as your interface to manipulating these DirectoryEntry objects (which you'll be storing in MyLinkedLists).
If two arguments are provided, use these values for the filenames of the personal and directory files.
% java Directory <personal.txt> <directory.txt>
If one is specified, use it for the personal file, and assume "directory.txt" for the other.
% java Directory <personal.txt>
If none is specified, use "directory.txt" for the directory and "personal.txt" for the personal.
% java Directory
The directory file should be considered a read-only list similar to your phone book -- don't add or remove from it.
The personal file (personal.txt) contains your personal address book. There may be duplicates between this file and the directory.
Entries are to be stored between runs of the program in flat text files. The format of the files is one entry per line with fields separated by ':' characters.
First:Middle:Last:Degree:Major:Rank:Email:Dorm
For splitting the line, you might want to look at String.indexOf() methods or String.split().
Note that there will be many entries with blank values such as no dorm or middle name listed.
Your Directory program should support the following operations. You may implement additional functions for consideration for extra credit.
Save personal list to a file -- only save when the user requests it
Here's how to create a PrintWriter
PrintWriter outFile=new PrintWriter(
new BufferedWriter(
new FileWriter("personal.txt")));
and now you can use 'outFile' just like 'System.out'
outFile.println("This line will be in personal.txt");
outFile.print("this has no newline");
Note: when you are done writing to your file, you need to close it. Normally, this is done when your program exits, but students have been reporting problems with this.
outFile.close();
Recall that you are implementing MyLinkedList so that it has a subset of the java.util.LinkedList methods. This means that you can build and test your Directory application separate from the MyLinkedList program. However, you need to first write the DirectoryEntry class that you will be using.
Notice how there are many similar actions in the above? Perhaps you can create methods to take care of such instead of having duplicated code.
Look through your programs and make sure you've included your name at the top of all of them.
You need to create a file called "README" that contains the following information:
If you have suggestions for improvements to this lab, feel free to add them to this file too.
If you adhered to the honor code in this assignment, add the following statement to your README file:
I affirm that I have adhered to the Honor Code in this assignment.
You now just need to electronically handin all your files. Assignment is 4.
Don't forget to run lshand and verify that things were submitted.
This lab is intended to: