CSC 241- Assignment#4--Extra Credit (Due December 16, 2002) [20 Points]
A Rolodex Application
Develop a rolodex application program that provides users with
the following options:
- Find someone's phone number.
- Add a name/phone number.
- Remove a name and its phone number from the rolodex.
- Change someone's phone number.
- Display partial/full list of name/phone numbers.
rolodexEntry
in order to develop the application program, you will need to first
develop a rolodexEntry class that implements
Comparable. This class must have two fields: name and
phone number. It needs a compareTo method, and
a toString method. This class is similar to
elementForTest class used in test2 from lab#5.
The compareTo method must return the result of comparing the name
field of its parameter against the object's own name field. The toString method
must concatenate name and phone number of the object as a String and return
that.
rolodexApp
Rolodex application keeps name/phone numbers in
a Tree. Use test2 used in lab5 as a template and follow the
algorithm given below:
- construct a set as either a tree or hashTable.
- loop forever
- Using, simple a series of System.out.printlns,
provide a menu:
1. Find an Entry
2. Add an Entry
3. Delete an Entry
4. Update Phone Number
5. Display partial/full list of name/phone numbers
6. Quit
- Get user's choice. testSamePercentage.java
should be looked at here to see how one reads from standard input and convert
a string to a number.
- switch choice
- case 1: prompt for and read a name;
create a rolodexEntry object with just the name, find it in the set;
output phone number in the object returned or
a NOT FOUND message when null is returned. break
- case 2: prompt for and read a name and phone number;
create a rolodexEntry; use the find method to see if it is already in
the set; if not, add the entry.
output success or failure. break.
- case 3: prompt for and read a name to delete.
create a rolodexEntry using just the name; use the find method
to see if it is in the set; if it is, remove the entry.
output success or failure. break.
- case 4: prompt for and read a name and a new phone number.
create a rolodexEntry object with the name only, find it in the set;
If in the set, change phone number field of the entry returned to the
phone number read.
output success or failure. break.
- case 5: Display partial/full list of name/phone numbers
This option enables the user to either see all names/phone numbers
or a partial set of them.
prompt for a partial name/*. Lets assume the user
response is stored in w. If w is a "*", all
name/phone numbers are displayed, otherwise, the subset of the
elements whose name start with the content of w are displayed.
For example, if w is "la", all names in the rolodex that start
with the substring la are displayed. Keep in mind that
the toArray returns all elements from the set in an array,
so you can use it to return all name/phone numbers and selectively
display what you need.
- case 6: return.
- End Switch
- End Loop
What to Turn In
rolodexApp.java and rolodexEntry.java files.