1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
choli [55]
3 years ago
5

Write a telephone lookup program. Read a data set of 1,000 names and telephone numbers from a file that contains the numbers in

random order. Handle lookups by name and also reverse lookups by phone number. Use a binary search for both lookups.
Computers and Technology
1 answer:
morpeh [17]3 years ago
4 0

Answer:

See explaination

Explanation:

PhoneLookup.java

import java.io.FileReader;

import java.io.IOException;

import java.util.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();

LookupTable 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.reverseLookup(n));

}

}

}

}

LookupTable.java

import java.util.ArrayList;

import java.util.Collections;

import java.util.Scanner;

/**

A table for lookups and reverse lookups

*/

public class LookupTable

{

private ArrayList<Item> people;

/**

Constructs a LookupTable object.

*/

public LookupTable()

{

people = new ArrayList<Item>();

}

/**

Reads key/value pairs.

atparam in the scanner for reading the input

*/

public void read(Scanner in)

{

while(in.hasNext()){

String name = in.nextLine();

String number = in.nextLine();

people.add(new Item(name, number));

}

}

/**

Looks up an item in the table.

atparam k the key to find

atreturn the value with the given key, or null if no

such item was found.

*/

public String lookup(String k)

{

String output = null;

for(Item item: people){

if(k.equals(item.getName())){

output = item.getNumber();

}

}

return output;

}

/**

Looks up an item in the table.

atparam v the value to find

atreturn the key with the given value, or null if no

such item was found.

*/

public String reverseLookup(String v)

{

String output = null;

for(Item item: people){

if(v.equals(item.getNumber())){

output = item.getName();

}

}

return output;

}

}

Item.java

public class Item {

private String name, number;

public Item(String aName, String aNumber){

name = aName;

number = aNumber;

}

public String getName(){

return name;

}

public String getNumber(){

return number;

}

}

input.txt

Abbott, Amy

408-924-1669

Abeyta, Ric

408-924-2185

Abrams, Arthur

408-924-6120

Abriam-Yago, Kathy

408-924-3159

Accardo, Dan

408-924-2236

Acevedo, Elvira

408-924-5200

Acevedo, Gloria

408-924-6556

Achtenhagen, Stephen

408-924-3522

Note: Replace all the "at" with at symbol

You might be interested in
The Occupational Outlook Handbook is published by the Bureau of Labor Statistics.
nika2105 [10]
HEY THEIR

The correct answer is A. true.

It was written in 1948 by the bureau of Labor statistics .

HOPE IT HELPS YOU
7 0
2 years ago
An administrator has just added a new update to the WSUS server and she wants to test the update to the test group. Which of the
DENIUS [597]

Answer:

a. gpupdate /force

Explanation:

Based on the information provided within the question it can be said that if the administrator does not want to wait she can use the command gpupdate /force. This command allows the individual to update both the local Group Policy settings and Active Directory-based settings. This the force tag makes it so that the policy is immediately update.

6 0
3 years ago
This is Tim’s first job. He is not familiar with how the Internet is used at the workplace. Match the applications of Internet u
Gala2k [10]

Answer:

A - 2

B - 3

C - 5

D - 4

E - 1

Explanation:

A. Virtual private network : 2

This is very useful when you have to work from home or visiting a client and need access to files/applications just like if you were at the office.

B. Email :  3

Yes, this is basically why the Internet was created in the first place.

C. Social networking sites : 5

Social networks are indeed a great marketing tool, allowing to target potential customers very precisely.

D. Search engines :  4

Yes, to find information about new products for the company, how the competitors are doing and so on.

E. Video and web conferencing:  1

Another great tool for employees working from home for example, or for employees located in an office at the other side of the country.

4 0
3 years ago
Which of the following does NOT help a user navigate through a document?
FromTheMoon [43]

Answer:

Navigation Tabs

Explanation:

Navigation tab is used to switch between different pages that are shown in navigation tab. It is not used to navigate through the document.

Scroll bar is used to navigate through the document line by line. It has been shown on the right side of the document to move up and down the page.

Next page and previous page button used to navigate between pages of the documents.

7 0
3 years ago
(tco 7) the asp.net ajax client-side framework is loaded on the _____ for an asp.net web application.
jok3333 [9.3K]

a client-side framework is loaded on the client side, ie., the browser.

4 0
2 years ago
Other questions:
  • What type of Windows Server is the most likely server to be targeted by a computer hacker?
    13·2 answers
  • WILL MARK BRAINLIEST HELP
    8·2 answers
  • Hi I am Khine Mye and I want to ask you a question I don't know that is square root of 2 is 1.4 and how to get that 1.4 and plz
    8·1 answer
  • The author of ""Cyber-psychopathy: What Goes On in a Hacker’s Head"" states that a crucial component of computer hacking lies in
    6·1 answer
  • Suppose a process in Host C has a UDP socket with port number 6789. Suppose both Host A and Host B each send a UDP segment to Ho
    8·1 answer
  • In C, how could I use a command line input to remove certain characters from an existing string? For example, if I have string '
    8·1 answer
  • Cable Internet access can be described with which feature?
    5·2 answers
  • How do you find a single number or name you want in a
    7·1 answer
  • Which of the following is a database concept that allows for storage and analysis for a dozen to billions of data points?
    7·1 answer
  • Greenpeace used "Mister Splashy Pants" to:
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!