I haven't touched Java in 2 years and I'm now required to do a data structures class...I wasn't very good with Java back then and now I'm very rusty so have some patience with me please. Sorry this is long but I wanted to make sure everyone knew what I am trying to do.
I have the command line based "interface" completed the main method is here.
Here's what I need to do:
Your program will be a simple address book. It will store names (used as keys) and addresses that are associated with the names. The program will present the user a menu with a choice of operations: add a name (and address), look up a name (displaying the associated address), update the address for a name, delete an entry, display all entries, and quit.
If the user chooses add the program prompts for a name. If the name already exists in the address book a message is displayed to that effect and no change is made. Otherwise the program asks for an associated address and the new entry is made. If the user chooses look up he or she is asked for a name. The program will look up the entry for that name and display the associated address. If the user chooses update he or she is asked for a name. The name is looked up and the address displayed. The user is then prompted for a new address which is accepted and stored in place of the old address. For delete the user is asked for a name and the entry for that name is removed from the address book. In any of these cases (other than insert) if the name given by the user is not found an appropriate message is displayed. If the user selects display all all of the names and addresses in the address book are displayed (the order is not important). The program continues displaying the menu and taking commands until the user chooses quit.
Names and addresses will occupy a single line (so all user input is taken using System.in.nextLine()). If the user enters a selection which is not in the menu the menu will be displayed again and the user is prompted again for a command. The names and addresses can be any strings -- your program need not check that they make any sense.
You will write (among other classes) a class Table which will store entries which are (key/value) pairs of Strings. You will need to write a Node class which will have (as private fields) a key String (used to identify the entry) and a value String (used to store some data associated with the key) and a next pointer used for linking. Table will have public methods:
+ • public boolean insert(String key, String value) Inserts a new entry to the table. If an entry already exists with the given key value make no insertion but return false.+
+ • public String lookUp(String key) Looks up the entry with the given key and returns the associated value. If no entry is found null is returned.+
+ • public boolean delete(String key) Deletes the entry with the given key. If no entry is found returns false.+
+ • public boolean update(String key, String newValue) Replaces the old value associated with with the given key with the newValue string.+
+ • public boolean markToStart() Sets the mark (see below) to the first item in the table. Returns false if the table is empty.+
+ • public boolean advanceMark() Moves the mark to the next item in the table. If there is no next item (e.g. at the end of the list) returns false.+
+ • public String keyAtMark() Returns the key stored in the item at the current mark.+
+ • public String valueAtMark() Returns the value stored in the item at the current mark.+
Table will keep a linked list of Nodes. Each entry (from the methods listed above) will be stored in an instance of Node stored in this linked list. The list is maintained in no particular order, but no two Nodes in the list can have the same key field.
Table will also have a (private) field, mark, which is a reference to Node. This field is modified or used by the markToStart, advanceMark, keyAtMark, and valueAtMark methods. Together these methods can be used to traverse the list and read the contents of all the entries in the table.
You may add any more methods you need to the Table class but they must be private. The only public methods are those listed above. All instance fields in all classes in your program will be private.
You will notice that this Table class is not specifically an address book but just stores and operates on pairs of strings. You will implement your address book as an instance of Table and will implement the address book operations, listed at the beginning of this page, using public methods of Table.
So here's what my problem is....
What goes into the Node class?
What else goes into the Table class?
Is there some other class I need?
I have an AddressBook class that has the command line based interface and I'm using a switch statement for that.
Each class is in a separate file.
I really DO want to figure this out on my own but seem to have hit wall. Lack of sleep maybe.....I just can't seem to get through this.
Thank is advance,
S-
I have the command line based "interface" completed the main method is here.
Here's what I need to do:
Your program will be a simple address book. It will store names (used as keys) and addresses that are associated with the names. The program will present the user a menu with a choice of operations: add a name (and address), look up a name (displaying the associated address), update the address for a name, delete an entry, display all entries, and quit.
If the user chooses add the program prompts for a name. If the name already exists in the address book a message is displayed to that effect and no change is made. Otherwise the program asks for an associated address and the new entry is made. If the user chooses look up he or she is asked for a name. The program will look up the entry for that name and display the associated address. If the user chooses update he or she is asked for a name. The name is looked up and the address displayed. The user is then prompted for a new address which is accepted and stored in place of the old address. For delete the user is asked for a name and the entry for that name is removed from the address book. In any of these cases (other than insert) if the name given by the user is not found an appropriate message is displayed. If the user selects display all all of the names and addresses in the address book are displayed (the order is not important). The program continues displaying the menu and taking commands until the user chooses quit.
Names and addresses will occupy a single line (so all user input is taken using System.in.nextLine()). If the user enters a selection which is not in the menu the menu will be displayed again and the user is prompted again for a command. The names and addresses can be any strings -- your program need not check that they make any sense.
You will write (among other classes) a class Table which will store entries which are (key/value) pairs of Strings. You will need to write a Node class which will have (as private fields) a key String (used to identify the entry) and a value String (used to store some data associated with the key) and a next pointer used for linking. Table will have public methods:
+ • public boolean insert(String key, String value) Inserts a new entry to the table. If an entry already exists with the given key value make no insertion but return false.+
+ • public String lookUp(String key) Looks up the entry with the given key and returns the associated value. If no entry is found null is returned.+
+ • public boolean delete(String key) Deletes the entry with the given key. If no entry is found returns false.+
+ • public boolean update(String key, String newValue) Replaces the old value associated with with the given key with the newValue string.+
+ • public boolean markToStart() Sets the mark (see below) to the first item in the table. Returns false if the table is empty.+
+ • public boolean advanceMark() Moves the mark to the next item in the table. If there is no next item (e.g. at the end of the list) returns false.+
+ • public String keyAtMark() Returns the key stored in the item at the current mark.+
+ • public String valueAtMark() Returns the value stored in the item at the current mark.+
Table will keep a linked list of Nodes. Each entry (from the methods listed above) will be stored in an instance of Node stored in this linked list. The list is maintained in no particular order, but no two Nodes in the list can have the same key field.
Table will also have a (private) field, mark, which is a reference to Node. This field is modified or used by the markToStart, advanceMark, keyAtMark, and valueAtMark methods. Together these methods can be used to traverse the list and read the contents of all the entries in the table.
You may add any more methods you need to the Table class but they must be private. The only public methods are those listed above. All instance fields in all classes in your program will be private.
You will notice that this Table class is not specifically an address book but just stores and operates on pairs of strings. You will implement your address book as an instance of Table and will implement the address book operations, listed at the beginning of this page, using public methods of Table.
So here's what my problem is....
What goes into the Node class?
What else goes into the Table class?
Is there some other class I need?
I have an AddressBook class that has the command line based interface and I'm using a switch statement for that.
Each class is in a separate file.
I really DO want to figure this out on my own but seem to have hit wall. Lack of sleep maybe.....I just can't seem to get through this.
Thank is advance,
S-