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
denis-greek [22]
3 years ago
14

1. 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:
Fed [463]3 years ago
3 0

Answer:

Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol

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.

     "at"param 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.

     "at"param k the key to find

     "at"return 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.

     "at"param v the value to find

     "at"return 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

Kindly check the attached output image below.

You might be interested in
question 2 what are some types of software that you'd want to have an explicit application policy for? check all that apply.
zaharov [31]

The types of software that you'd want to have an explicit application policy are:

  • Filesharing software
  • video games

  • Explicit application policy are simply refered to as legal rights that are stated regarding ownership or company. It is actual substance of an agreement

  • Video games and filesharing software is of not really important in som business. So therefore, having explicit policies showing why or not this type of software is permitted on systems is okay.

Conclusively, we can say that Filesharing software and video games can require an explicit application policy.

Learn more from

brainly.com/question/12730075

4 0
2 years ago
Which kind of photography takes attractive photos of products to make them stand out?
CaHeK987 [17]

Answer:

See there are multiple ways to get a perfect shot of products to stand out but the most affective according to me are explained below :-

  • Macro shooting - These are close shots u can say really close just to show the product more attractive and u can see these types of shots in every advertisement.
  • Background shooting/shots - Opposite of macro shots.
  • 3d shots - These are 360° shots.

Tip :- Use wide aperture like F2 and right aperture for right shots.

Hope it helps!

3 0
3 years ago
A two-dimensional array of ints, has been created and assigned to a2d. Write an expression whose value is the number of rows in
Contact [7]

Explanation:

oi.........................

7 0
3 years ago
What project started the development of inter-network connections using tcp/ip that has evolved into the internet today.?
rosijanka [135]
Dial Up, help start it
3 0
3 years ago
How did domestication of maize make the city of tenochtitlan possible?
umka21 [38]

The farming of maize began in Mesoamerica in 6000 B.C. The domestication of maize made the city of Tenochtitlan possible by providing the Aztecs the ability to feed millions. Unlike the corn that is known today, the early maize had tiny cobs but dramatically became bigger and more nutritious as time passed.


3 0
3 years ago
Read 2 more answers
Other questions:
  • An airline company would like to easily locate lost luggage. What technology would make it easier for them to locate the luggage
    6·2 answers
  • Brainly is the stupidest homework site. The past like 10 questions ive asked ive had no answer to. Thanks a lot!
    9·1 answer
  • The commands available here change depending on the activity taking place in the presentation window's main work area.
    15·2 answers
  • The color band that represents tolerance on a resistor is the?
    11·1 answer
  • Most people entering the construction industry learn a specific craft through:
    14·2 answers
  • A blue NFiPA label indicates: A) Health Hazard B) Special information C) Flammability D) Reactivity
    6·2 answers
  • A vacuum tube that contains a grid can be classified as a A. rectifier B. triode C. pentode D. diode
    12·1 answer
  • Free brainliest!?! &lt;3​
    9·2 answers
  • Fill in the table below of the Interactive Word Wall. You are provided with the
    13·1 answer
  • I am having trouble with this python question. I am in a beginner level class also so any solution that isn't too complex would
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!