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
We can include following item(s) during configuration itemidentification:
Ainat [17]

Answer:

d) All of the above

Explanation:

In configuration management, the Identify configuration items, work products and related components are present.

  • All the documents which are related to the work,the manuals how that the system works are present in the configuration item identification.
  • The source code that is implement for the functioning of the products.These are implemented at the time of generation of products.
  • Software Requirement Specifications are also specified by SRS it is present in design stage of software development life cycle,it is also a part of configuration item identification.
5 0
3 years ago
What is the term for a set of actions carried out on inputs?
Ymorist [56]

Answer:

<u><em>Input Bindings</em></u> is the term that is used for actions carried out on inputs in automation process.

Explanation:

In Automation process different operation or tasks had been performed such as output, input, internal actions. These are known as action bindings.

At input terminal the actions that are being carried out are called Input bindings. A command is comes from control pin and data is comes from input pin. This input and control signal combines together and perform the action that is required by machine or device.

<em>This is the reason these actions performed at input device is called Input Binding.</em>

8 0
3 years ago
The button for adding a picture to a spreadsheet is found in the
boyakko [2]
The answer is Insert Tab. This is the button to add a picture to a spreadsheet.  <span>Click </span>Insert to add something to a spreadsheet. This includes pictures, shapes, charts, links, text boxes, video and more. <span>The </span>Insert Tab<span> is used to </span>insert<span>    different features such as tables, pictures, clip art, shapes, charts, page numbers, word art, headers, and footers into a document. </span>
6 0
3 years ago
How did The Gates by Christo and Jeanne-Claude affect the site?
Nadusha1986 [10]

Answer:

C. The experience of the park with The Gates was so different that some people saw the park in a new way.

Explanation:

The couple, Christo Javacheff and Jeanne-Claude Denat based in New York were two top contemporary artists who formed collaborative arts.

On the 3rd of January, 2005 they both made an art work known as The Gates, in Central Park.

The experience of the park with "The Gates" was so different that some people saw the park in a new way.

8 0
3 years ago
Read 2 more answers
The PowerPoint view in which you can edit the slide master is called ______________.
nirvana33 [79]

Answer:

it's slide master view.

8 0
2 years ago
Other questions:
  • Given positive integer numInsects, write a while loop that prints that number doubled without reaching 100. Follow each number w
    8·1 answer
  • Which of the following is a goal of paraphrasing​
    12·1 answer
  • A superscope is a special type of scope that allows a dhcp server to service multiple ipv4 subnets on multiple physical networks
    7·1 answer
  • Discuss advantages and disadvantages of Twisted Pair?
    6·1 answer
  • A technician is configuring a new SOHO multifunction wireless router at a customer’s location to provide network access to sever
    12·1 answer
  • Please tell me what is basic HTML tags and its function please ​
    8·1 answer
  • Hydraulic systems use liquids because _____.
    14·2 answers
  • Rachael has been posting negative comments on several of her peers' social media pages. Which of the six Ps is Rachael abusing?
    15·1 answer
  • Given the following sets, for each set operation provide the elements of the resulting set in set notation or using a well-known
    5·1 answer
  • Instant Search can NOT be used to search through archived messages.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!