HELP IN JAVA: Write a telephone lookup program. Read a data set of 1000 names an
ID: 3709240 • Letter: H
Question
HELP IN JAVA: Write a telephone lookup program. Read a data set of 1000 names and telephone numbers from files that contain contact information. Your program has to work like a caller ID system, where given a number it displays the name. (There will be no duplicate names or numbers.) Use selection sort for sorting. Use a binary search for lookup.
The program has to do two things: read in the data and handle user queries.
1. The data is in two files. For each person, the name is listed in one file and the phone number is listed in the other. The first phone number belongs to the first person, the second number to the second person etc. Create a Contact class (name and phone number are the only attributes), make Contact objects and put them in an array.
2. The program should prompt the user with this message: “Please enter a phone number, or * to quit.” The user enters a phone number, and the program prints the name and the phone number (separated by a space) for the corresponding contact. If a match cannot be found, the program should print “Unknown number.” Repeat this until the user enters *.
names.in:
Eduardo Ashley
Aryana Foley
Emmy Richmond
Alfredo Meadows
Chaz Bailey
Kael Hurst
Jayden Ho
Alissa Armstrong
Andre Warner
Emelia Duffy
Lilah Oneal
Reece Saunders
Leslie Long
Carleigh Roy
Lauryn Kelley
Yahir Gibson
Jon Farrell
Noel Keller
Prince Rush
Mohamed Ferguson
Kenny Welch
Vaughn Cortez
Davin Taylor
Ellis Krause
Camren Ewing
Gustavo Larson
Adyson Sutton
Eric Carroll
Sadie Ryan
Dale Montoya
Braylen Lopez
Karen Blankenship
Cristofer Gamble
Destiney Goodwin
Diya Bradley
Xander Holden
Colt Petty
Kason Clements
Amirah Norton
Griffin Woodard
Mathias Meza
Kamren Haynes
Yaretzi Dunlap
Maxim Ware
Joshua Blackburn
Talan Daniels
Arturo Barron
Jessie Flowers
Amare Riddle
Jamie Lucas
Juliette Gentry
Maxwell Wilkinson
Elizabeth Joseph
Mila Mullins
phonenumbers.in:
486-685-8308
711-493-6467
871-805-7191
914-344-2341
972-724-5804
688-676-8778
533-157-4369
773-441-5964
982-299-7011
738-457-5223
584-697-4026
640-546-8525
676-413-4555
346-798-2986
197-558-7174
981-219-5396
629-886-0613
264-695-7432
578-443-3637
143-383-2607
177-653-7196
512-256-3102
580-274-8598
103-408-1270
794-811-5176
517-936-8730
557-544-6007
259-206-0803
130-288-9748
508-125-7545
402-978-6192
456-224-8998
834-480-4026
104-999-3709
929-108-4589
806-359-7192
979-845-1137
115-268-7117
688-208-6629
852-965-4901
201-932-8537
714-617-0074
365-176-3853
508-226-6881
525-361-5968
577-969-7112
767-364-8075
909-304-2026
251-860-7513
313-916-2862
981-632-5070
834-570-4414
405-745-8109
663-575-4411
Explanation / Answer
import java.io.IOException;
import java.io.FileReader;
import java.Scanner;
public class PhoneLookup
{
public static void main(String args) throws IOException
{
Scanner in = new
Scanner(System.in);
System.out.println("Enter the name of the phonebook file: ");
string fileName = in.nextline();
Lookup Table table = new
LookupTable();
FileReader reader = new
FileReader(fileName);
table.read(new Scanner(reader));
boolean more = true;
while(more)
{
System.out.println("Lookup N)ame, P)hone number, Q)uit?");
String cmd = in.nextLine();
if(cmd.equalsIgnoreCase("Q"))
more = false;
else if
(cmd.equalsIgnoreCase("N"))
{
System.out.println("Enter name:");
String n =in.nextLine();
System.out.println("Phone number:"+table.lookup(n));
}
else if
(cmd.equalsIgnoreCase("P"))
{
System.out.println("enter phone number:");
String n = in.nextLine();
System.out.println("Name:"+table.reversalLookup(n));
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.