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
People often want to save money for a future purchase. You are writing a program to determine how much to save each week given t
GenaCL600 [577]
.................................
7 0
3 years ago
Read 2 more answers
Who is in the age range of 13-15 and wants to join a mine craft smp?
Ratling [72]

Answer: Wow that's really cool!

3 0
3 years ago
Two people can verify they are communicating with each other by using a ____________, which verifies each party's identity by be
photoshop1234 [79]

Answer:

b. Certificate Authority

Explanation:

Based on the information provided within the question it can be said that they are communicating with each other by using a certificate authority. This term refers to a company or organization that provides security verification by issuing both parties cryptographic keys which are specifically verified by the company in order to allow both parties to know exactly who they are communicating with.

5 0
3 years ago
Use rounding to decide if the answer is reasonable. Write
erik [133]

Answer:

348 + 395 = 743

Hence, together they have 743 pennies and not 653 pennies. And we cannot perform the rounding, as that is the case when we have the decimal number or the float number. Only then we have the digits after the decimal. And if it's more than 5, we add 1 to the previous or else leave the number as it is. And we go on performing from right to left, and till the number of decimal places, we need to round off. However, here its purely an integer, and hence we cannot round off, as that will result in a significant loss, and which is not acceptable. However, if we want to round off before decimal places as well, then in that case 743 will be $7s, and 653 pennies will be 6+1= $7s, and if this level of loss is acceptable then we can assume that they have the same sum of money. However, here the answer is given in pennies, and hence this is not the case. And hence the answer given in the question is not correct.

Explanation:

The answer is self-explanatory. And since both are numbers, rounding is not required(as explained in the answer section), as it is required in case of decimal and float(as explained in the answer section). And as explained in the answer section, if we can tolerate very heavy loss, then the numbers as well can be rounded off as explained in the answer section. But that is not the case here, as the answer is given in pennies.

6 0
3 years ago
WILL GIVE 50 POINTS AND GIVE BRAINIEST TO THE FIRST PEOPLE THAT ANSWER CORRECTLY!!!!!! Luis receives a workbook from a classmate
k0ka [10]

Answer:

the third one

Explanation:

4 0
3 years ago
Read 2 more answers
Other questions:
  • Numeric data is stored in ___________ for direct processing.
    10·2 answers
  • Your mobile device files can be synchronized using ________. hdmi a secure digital transmission a display adapter a cloud servic
    11·1 answer
  • .exe, .msi, .msp, .inf - together, what do these filetypes indicate
    12·2 answers
  • Which type of attack modifies the fields that contain the different characteristics of the data that is being transmitted?
    7·1 answer
  • What is the difference, if any, between secure HTTP and firewalls?
    13·1 answer
  • An app where you spin a wheel for coins and exchange for giftcards
    6·1 answer
  • The information provided in text aids can help us to understand a text’s content before we even read it.
    8·1 answer
  • Many web pages use a <br> structure to define an area of focus
    13·1 answer
  • PLZZZ HELP!!!!!!!
    12·1 answer
  • What is the most used gaming keyboard in 2022?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!