For this assignment, you implement two classes that will serve as the foundation of a simple key/value database. A programmer could use your database to implement a note-taking program, where each note has a label and consists of some text. It could also be used to implement a phone directory or a calendar or a writer's planning program.
We will extend this program a couple of times throughout the semester as we learn more about Java and object-oriented programming.
Your programming task is defined below as a sequence of small requirements. Write your program by implementing one requirement at a time in order. That is how we will grade your program.
Programming Advice
As always, write your program in the style we first learned in Session 1:
Take small steps, and your tests will give you feedback as soon as possible. Use the GenerateTest program to create your test class.
Evaluating the Program
To evaluate the functionality of your submission, we will do two things:
As soon as we encounter a requirement that is not satisfied, we will stop grading. So solving an item lower in the list won't be of any use to you if the you haven't completed the tasks that precede it in the list.
Let's expand our knowledge of Java with this program.
Comparing Two Objects
In Java, we compare two objects using the equals(Object obj) method. Notice that the argument to this method is of type Object. As a result, we write a method of this sort:
public boolean equals(Object obj) { if (! obj instanceof CLASSNAME) return false; CLASSNAME name = (CLASSNAME) obj; // ... code to compare receiver to the argument }
... where CLASSNAME is the name of the class that contains the method. If obj is an instance of CLASSNAME, we cast it as such so that we can treat it as such. (This method overrides the equals() defined in class Object.)
Working with Strings
Strings respond to many useful messages that we can use to work with them. In particular, a String will find substrings of itself and compare itself to another String.
Vector, A Dynamically-Sized Collection
One of the shortcomings of using arrays is that we have to know exactly how many objects we need. But in many programs we don't know the number of objects we store until we execute the program.
In such situations, we can use a Vector to hold our objects. Unlike an array, a Vector can hold any number of objects and will grow as necessary. Here are some standard ways to work with Vectors:
for (int i = 0; i < vectorOfFrames.size(); i++) { (Frame) frame = (Frame) myVector.elementAt(i); // ... process frame }
If you have any questions about these new Java ideas, please ask questions soon! You do not need to scour the web for more information about these classes and methods, beyond the on-line Java documentation linked.
Write tests and code for each of the following requirements, in order. The words in bold indicate message names. Whenever a requirement says the user can "ask whether...", the expected answer is boolean. Whenever a requirement speaks of a "particular" item, then that item will be an argument to the method.
[key]:[value]
You may not add so-called access methods to the Association class. That is, you may not add "get" or "set" methods, whose only behavior is to return a field's value or assign a field's value, respectively.
By the due date and time, submit the files
Be sure that your submission follows all homework submission requirements.