I already have the code for the assignment below, but there is some errors in the code. Please help me fix them. The assignment: Make 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. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help.    The code: 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 people;    /**       Constructs a LookupTable object.    */    public LookupTable()    {        people = new ArrayList();    }    /**       Reads key/value pairs.       @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.       @param k the key to find       @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.       @param v the value to find       @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;    } }   The error is shown in the picture I attached, please have a look at the picture.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I already have the code for the assignment below, but there is some errors in the code. Please help me fix them.

The assignment:

Make 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. This assignment needs a resource class and a driver class. The resource class and the driver class will be in two separate files. The resource class will contain all of the methods and the driver class only needs to call the methods. The driver class needs to have only 5 lines of code. The code needs to be written in Java. Please help me with exactly what I asked for help. 

 

The code:

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.
      @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.
      @param k the key to find
      @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.
      @param v the value to find
      @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;
   }
}

 

The error is shown in the picture I attached, please have a look at the picture. 

 

import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;
A table for lookups and reverse lookups
// LookupTable class
public class LookupTable
{
private ArrayList<Item> people;
/**
Constructs a LookupTable object.
* /
public LookupTable()
people = new ArrayList<Item>();
}
Reads key/value pairs.
@param in the scanner for reading the input
G U9E02R. G U9E02D. G U9P08R. G U9P08D. G U9P07R. G U9P07. GU10E03. GU10E02.CU10E02. C U9P03R. C U9PO3.
Compile Messages
JGRASP Messages
Run l/O
Interactions
----JGRASP exec: javac -g U10E08R.java
U10E08R.java:11: error: cannot find symbol
private Arraylist<Item> people;
Stop
Clear
Сору
symbol:
class ArrayList
location: class U10E08R
U10E08R. java:18: error: cannot find symbol
people = new ArrayList<Item>();
symbol:
class ArrayList
I
location: class U10E08R
U10E08R.java:30: error: no suitable constructor found for Item(String,String)
people.add(new Item(name, number));
constructor Item.Item() is not applicable
(actual and formal argument lists differ in length)
constructor Item.Item(double, boolean, int) is not applicable
5:47 / 1:30:00
Transcribed Image Text:import java.io.FileReader; import java.io.IOException; import java.util.Scanner; A table for lookups and reverse lookups // LookupTable class public class LookupTable { private ArrayList<Item> people; /** Constructs a LookupTable object. * / public LookupTable() people = new ArrayList<Item>(); } Reads key/value pairs. @param in the scanner for reading the input G U9E02R. G U9E02D. G U9P08R. G U9P08D. G U9P07R. G U9P07. GU10E03. GU10E02.CU10E02. C U9P03R. C U9PO3. Compile Messages JGRASP Messages Run l/O Interactions ----JGRASP exec: javac -g U10E08R.java U10E08R.java:11: error: cannot find symbol private Arraylist<Item> people; Stop Clear Сору symbol: class ArrayList location: class U10E08R U10E08R. java:18: error: cannot find symbol people = new ArrayList<Item>(); symbol: class ArrayList I location: class U10E08R U10E08R.java:30: error: no suitable constructor found for Item(String,String) people.add(new Item(name, number)); constructor Item.Item() is not applicable (actual and formal argument lists differ in length) constructor Item.Item(double, boolean, int) is not applicable 5:47 / 1:30:00
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY