Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am really in need of help with this program I am so lost and none of the solut

ID: 3844830 • Letter: I

Question

I am really in need of help with this program I am so lost and none of the solutions people are giving are correct I have posted 10 times already with no help so I would really appreciate a correct answer by know! Thank You for your help I aprreciate it. In JAVA (you can use NetBeans compiler), write a PhoneBook that will have FOUR SEPERATE CLASSES, please make them distinct.

Person: which represents the name and phone number of a person, you will store instances of this class in the phone book

PhoneBook: which represents the phone book. The class should contain a binary search tree as a data field. This tree contains the people in the book.

Menu: which provides the program’s user interface—contains a main() method which creates a PhoneBook object, displays the PhoneBook’s methods as different menu selections and invokes the PhoneBook method the user selects

HashTable: which is the ADT HashTable. This is the class which contains the PhoneBook’s collection of data (all of the People objects in the PhoneBook), as well as the operations which can be performed on that collection of data.

This Phone book should be able to...

Add: Adds a person’s name and phone number to the phone book.

Delete: Deletes a given person’s name and phone number from the phone book, given only the name.

Find: Locates a person’s phone number, given only the person’s name.

Change: Changes a person’s phone number, given the person’s name and new phone number.

Quit: Quits the application, after first saving the phone book in a text file.

The key to this project is in the implementation of a hashCode() method, which “translates” a key value into a numeric index value, which identifies the location in which an item will be “stored” in the hash table. You must also consider how to resolve a “collision”. This is when two key values are translated into the same index value. Thank You!

Explanation / Answer

import java.io.*; public class Phones { static final String DEFAULT_FILENAME = "phones.dat"; static PhoneDirectory directory; // Holds the data for // the phone directory. public static void main(String[] args) { String fileName; // Name of file that stores the directory data. boolean done; // Set to true when the user wants to exit the program. /* Get the file name from the command line, or use the DEFAULT_FILENAME if there is no command-line argument. */ if (args.length == 0) fileName = DEFAULT_FILENAME; else fileName = args[0]; /* Read the phone directory data from the file. This routine might terminate the program if an error occurs when the attempt is made to end the data. */ readPhoneData(fileName); /* Show user a menu of available operations, get the user's choice, and carry it out. Repeat until the user selects the "Exit from this program" operation. Each of the other four commands is carried out by calling a subroutine. */ done = false; while (done == false) { TextIO.putln(); TextIO.putln(); TextIO.putln("Select the operation you want to perform:"); TextIO.putln(); TextIO.putln(" 1. Look up a phone number"); TextIO.putln(" 2. Add an entry to the directory"); TextIO.putln(" 3. Delete an entry from the directory"); TextIO.putln(" 4. Change someone's phone number"); TextIO.putln(" 5. Exit form this program."); TextIO.putln(); TextIO.put("Enter the number of your choice: "); int menuOption = TextIO.getlnInt(); switch (menuOption) { case 1: doLookup(); break; case 2: doAddEntry(); break; case 3: doDeleteEntry(); break; case 4: doModifyEntry(); break; case 5: done = true; break; default: System.out.println("Illegal choice! Please try again."); } // end switch } // end while /* If the phone directory data has been modified, write the changed data back to the file. */ if (directory.changed == true) writePhoneData(fileName); TextIO.putln(" Exiting program."); } // end main() static void readPhoneData(String fileName) { // Get the data for the phone directory from the specified // file. Terminate the program if an error occurs. If the // file does not exist, give the user the option of creating // it. TextReader in; // A stream for reading the data. try { // Try to create a stream for reading from the file. // If the file is not found, set the value of in to null. in = new TextReader( new FileReader(fileName) ); } catch (Exception e) { in = null; } if (in == null) { // The specified file could not be opened. Give the // user the option of creating a new, empty file. TextIO.putln(" The file "" + fileName + "" does not exist."); TextIO.put("Do you want to create the file? "); boolean create = TextIO.getlnBoolean(); if (create == false) { TextIO.putln("Program aborted."); System.exit(0); } directory = new PhoneDirectory(); // A new, empty phone directory. try { // Try to create the file. PrintWriter out = new PrintWriter( new FileWriter(fileName) ); directory.save(out); if (out.checkError()) throw new Exception(); TextIO.putln("Empty directory created."); } catch (Exception e) { TextIO.putln("Can't create file."); TextIO.putln("Program aborted."); System.exit(0); } } else { // The input stream was created successfully. Get the data. try { directory = new PhoneDirectory(); // A new, empty directory. directory.load(in); // Try to load it with data from the file. } catch (Exception e) { TextIO.putln("An error occurred while read data from "" + fileName + "":"); TextIO.putln(e.toString()); TextIO.putln("Program aborted."); System.exit(0); } } } // end readPhoneData() static void writePhoneData(String fileName) { // Save the data from the phone directory to the specified file. PrintWriter out; try { out = new PrintWriter( new FileWriter(fileName) ); } catch (Exception e) { TextIO.putln(" Can't open file for output!"); TextIO.putln("Changes have not been saved."); return; } directory.save(out); if (out.checkError()) { TextIO.putln("Some error occurred while saving data to a file."); TextIO.putln("Sorry, but your phone directory might be ruined"); } } static void doLookup() { // Carry out the "Look up a phone number" command. Get // a name from the user, then find and print the associated // number if any. TextIO.putln(" Look up the name: "); String name = TextIO.getln(); String number = directory.numberFor(name); if (number == null) TextIO.putln(" No such name in the directory."); else TextIO.putln(" The number for " + name + " is " + number); } static void doAddEntry() { // Carry out the "Add an entry to the directory" command. // This will only work if the name that the user specifies // does not already exist in the directory. If it does, // print an error message and exit. Otherwise, get the // number for that person from the user and add the entry // to the directory. TextIO.putln(" Add entry for this name: "); String name = TextIO.getln(); if (directory.numberFor(name) != null) { TextIO.putln("That name is already in the directory."); TextIO.putln("Use command number 4 to change the entry for " + name); return; } TextIO.putln("What is the number for " + name + "? "); String number = TextIO.getln(); directory.addNewEntry(name,number); } static void doDeleteEntry() { // Carry out the "Delete an entry from the directory" command. // Get the name to be deleted from the user and delete it. // If the name doesn't exist in the directory, print a message. TextIO.putln(" Delete the entry for this name: "); String name = TextIO.getln(); if (directory.numberFor(name) == null) TextIO.putln("There is not entry for " + name); else { directory.deleteEntry(name); TextIO.putln("Entry deleted."); } } static void doModifyEntry() { // Carry out the "Change someone's phone number" command. // Get the name from the user. If the name does not exist // in the directory, print a message and exit. Otherwise, // get the new number for that person and make the change. TextIO.putln(" Change the number for this name: "); String name = TextIO.getln(); if (directory.numberFor(name) == null) { TextIO.putln("That name is not in the directory."); TextIO.putln("Use command number 2 to add an entry for " + name); return; } TextIO.putln("What is the new number for " + name + "? "); String number = TextIO.getln(); directory.updateEntry(name,number); } } // end class Phones

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote