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]
2 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]2 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
Help me plz What character must always be used when a formula is enter in a cell? (on a spreadsheet)​
lara [203]

Answer:

The equal sign "=" must be used.

Most, if not all, spreadsheet programs support formulas, but you must start them with an equal sign.

8 0
2 years ago
You have a sales chart and excel that you want to include in a 3rd quarter report to include in a 3rd quarter report quit it in
Nataliya [291]

Answer:

The paste function to use is the Advanced Paste Function that reads Use Destination Theme and Link Data or Keep Source Formatting and Link Data.

Explanation:

The first function adopts the Theme (such as colors, fonts, and other formatting) whilst retaining links to the data in the excel workbook. The latter imports the formatting or theme as-is from excel.

In both scenarios, (for as long as both documents are open and are in the same file) when the data in excel is opened and updated, it reflects automatically in the chart on the Microsoft Word document.

Cheers

5 0
2 years ago
List and describe the three types of cloud models described by Microsoft.
anygoal [31]

There are three main service models of cloud computing – Infrastructure as a Service (IaaS), Platform as a Service (PaaS) and Software as a Service (SaaS). There are clear differences between the three and what they can offer a business in terms of storage and resource pooling, but they can also interact with each other to form one comprehensive model of cloud computing.

aaS (Infrastructure as Service)

This is the most common service model of cloud computing as it offers the fundamental infrastructure of virtual servers, network, operating systems and data storage drives. It allows for the flexibility, reliability and scalability that many businesses seek with the cloud, and removes the need for hardware in the office. This makes it ideal for small and medium sized organisations looking for a cost-effective IT solution to support business growth. IaaS is a fully outsourced pay-for-use service and is available as a public, private or hybrid infrastructure.

PaaS (Platform-as-a-Service)

This is where cloud computing providers deploy the infrastructure and software framework, but businesses can develop and run their own applications. Web applications can be created quickly and easily via PaaS, and the service is flexible and robust enough to support them. PaaS solutions are scalable and ideal for business environments where multiple developers are working on a single project. It is also handy for situations where an existing data source (such as CRM tool) needs to be leveraged.

SaaS (Software as a Service)

This cloud computing solution involves the deployment of software over the internet to variousbusinesses who pay via subscription or a pay-per-use model. It is a valuable tool for CRM and for applications that need a lot of web or mobile access – such as mobile sales management software. SaaS is managed from a central location so businesses don’t have to worry about maintaining it themselves, and is ideal for short-term projects.

3 0
3 years ago
Why is it important to register your software when you install it
Serjik [45]

the normal reasons program creators deliver to enroll your program – to get tech bolster, news, upgrades, offers, bug fixes, and so on. It too ensures your venture since it gives you changeless get to to your enlisted serial number in case something ever happens to your computer or computer program.

6 0
2 years ago
10 points if right...
aivan3 [116]

email because with chat it might wake up the kids and wbsite doesnt make sense. neither does blog so with email you can give personal messages and pictures.

7 0
2 years ago
Read 2 more answers
Other questions:
  • Write a script that creates a user-defined database role named OrderEntry in the MyGuitarShop database. Give INSERT and UPDATE p
    8·1 answer
  • What is the difference between First Person Shooters and Construction Simulations?
    12·2 answers
  • Develop an sec (single error correction) code for a 16-bit data word. generate the code for the data word 0101000000111001. show
    6·2 answers
  • The voluntary linkage of computer networks around the world is called the ______.
    7·1 answer
  • What fields of engineering are in Biomedical
    7·1 answer
  • Que es la felicidad??​
    12·1 answer
  • Which function would you use to make sure all names are prepared for a mailing label? TODAY UPPER PROPER LOWER
    11·1 answer
  • Suppose that a 64MB system memory is built from 64 1MB RAM chips. How many address lines are needed to select one of the memory
    11·1 answer
  • Please please help I don’t understand this
    6·1 answer
  • Guidewords for the word “serpent” may be
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!