Help telephone book application using maps
Im having trouble with an assignment that I was given. here is the assignment and the code I have so far.
The Telephone Lookup application
The goal of this assignment is to design and write a program that does a telephone lookup. The program reads a data set of names and telephone numbers from a file that contains the names and telephone numbers in random order. Your program must handle lookups by name and also reverse lookups by phone number.
You are to design and write a program that prompts the user for the name of the input file that contains names and telephone numbers of individuals. The file is NOT organized in any particular fashion (i.e. sorted). The program should offer the user a menu of choices as to looking up a telephone number given a name of an individual or looking up a name given a telephone number, or quitting. You must use Maps to solve this problem,
The text will come from an input file. (Use any input files to test your program but I will use my own to test.) The input file has the format:
The user should be prompted for the name of the file, and then given the choices of 1) lookup by name, 2) lookup by number, 3) quit. The program should run over and over until the user chooses quit.
If the user chooses 1) lookup by name, the output is the telephone number displayed on the console.
If the user chooses 2) lookup by number, the output is the name displayed on the console.
If the user chooses 3) quit, the program should terminate.
a. Write the algorithm for solving the problem 1st . Include it in the comment section of your code.
b. You must write the driver class called TelephoneLookup that :
• Reads data from a file
• Gives the user a menu of 3 choices: look up by name, look up by number, or quit
• Creates one or more Maps to store the names and associated telephone numbers.
• Based upon the choice above, does the appropriate action.
• Note: since you’re using Maps to solve this problem, you will NOT need any other classes other than the driver.
c. You can use any input file you'd like but I will use my own to test the program.
I no I need to set up another scanner to read in the users choice but Im not sure how. Please help.
public class TelephoneLookup
public static void main(String args)
Scanner console = new Scanner(System.in);
Scanner in = new Scanner(new File("TextIn.txt"));
Map<String, String> map = new TreeMap<String, String>();
String name = in.nextLine();
String number = in.nextLine();
boolean done = false;
System.out.println("Enter name if you want to loop up telephone number by name,");
System.out.println("Enter phone if you want to loop up name by telephone number,");
System.out.println("Enter quit if your done");
String input = in.next();
done = true;
else if (input.equalsIgnoreCase("name"))
System.out.println("Please enter the name");
String nameInput= in.next();
else if (input.equalsIgnoreCase("phone"))
System.out.println("Please enter the phone number");
String numberInput= in.next();
System.err.println("Cannot find input file " );
System.exit(1); // abnormal termination status code
System.err.println("Cannot open input file " );
Moderator Edit: Code tags added