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
Dеclarе and allocatе mеmory (on thе hеap) for a two-dimеnsional array of strings namеd carMakеs with 20 rows, еach with 6 column
Lena [83]

Answer:

string ** carMakes=new string*[20];  

   for(int i=0;i<20;i++)

   {

       carMakes[i]=new string[6];

   }

Explanation:

The above written piece of code is in C++ and it will declare and allocate memory on the heap for a 2-D array of strings with the number of rows 20 and number of columns 6 with name of the array carMakes.

To declare a 2-D array in C++ we use new keyword.

4 0
4 years ago
Why does the font­family css specification take a list rather than a single font name?
azamat
You can't guarantee that the computer displaying the page has all the fonts that you want. Generally for font-family (note the hyphen!) you list:

the font you REALLY want
a font that's similar and more common (you HOPE it has)
the family (like serif or san-serif)
5 0
4 years ago
Ensuring that all clients have access to services, resources, and opportunities despite challenges is an example of which ethica
lara [203]

Ensuring that all clients have access to services, resources, and opportunities despite challenges is an example of the ethical principle "justice".

<h3>What is ethical principle?</h3>

Ethical principles do not include a simple rule that assures making an ethically sound option, nor do they provide help on ranking whenever the principles seem to clash with one another.

Instead, they just point to factors that should be considered while making decisions.

Some characteristics of ethical principal are-

  • Ethical principles are elements of a normative theory that supports or defends moral standards and/or moral judgments; therefore are not based on one's subjective perspectives.
  • In public health practice, ethical principles are general judgments that serve as the foundation for the many specific ethical prescriptions & evaluations of public health actions.
  • A value can be differentiated from a principle. The value would be something people think is beneficial and should be more prevalent.
  • For example, honesty is a virtue. A principle is typically defined as a rule which puts a value in action.

To know more about ethical principle,here

brainly.com/question/4475592

#SPJ4

8 0
1 year ago
How is technology ruining human relationships
Gala2k [10]
Robots are taking our jobs and we cant earn any money for our family
8 0
3 years ago
Read 2 more answers
Imagine you plan to send 5 petabytes data from New York to San Francisco. You have two choices: (1) transfer data using your 200
Taya2010 [7]

Answer: UPS.

Explanation: Since there are around 1 Billion Megabytes in 1 Petabyte, 5,368,709,120 / 200 Mbps = 26,843,545 Seconds.

26,843,545 seconds = 310 Days.

UPS should be faster.

I hope I helped you out!

8 0
3 years ago
Other questions:
  • The condition, ____, entered in the criteria row of a long text field in a query window would retrieve all records where the lon
    8·1 answer
  • A digital device Select one: a. uses electricity to run it. b. uses symbolic representations of data in the form of code. c. req
    7·1 answer
  • Java and C++ are examples of _____.assembly languagehigh-level languagesmachine languagecompiler languages
    7·2 answers
  • Count characters Write a program whose input is a string which contains a character and a phrase, and whose output indicates the
    6·1 answer
  • Answer if you play PS4 apex legends if you do answer username and first to answer is brainliest
    15·2 answers
  • The pointer changes shape by adding a _____ to indicate that the format painter function is active.
    9·1 answer
  • Briefly describe the software quality dilemma in your own words
    13·1 answer
  • Software that displays advertising material when online.
    12·2 answers
  • If you are working in a word-processing program and need to learn about its features, the best place to get assistants is from t
    9·2 answers
  • Which pair of devices have the same input motion and different outputs?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!