I already have the code for the assignment below, but there are some errors in the code. Please help me fix the code.  The assignment: Continue Exercise •• P13.1, checking the words against the /usr/share/dict/words on your computer, or the words.txt file in the companion code for this book. For a given number, only return actual words.

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 are some errors in the code. Please help me fix the code. 

The assignment: Continue Exercise •• P13.1, checking the words against the /usr/share/dict/words on your computer, or the words.txt file in the companion code for this book. For a given number, only return actual words.

 

The code of resource class:

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;

public class U10P02R
{
 static ArrayList<String> words = new ArrayList<String>();
 U10P02R(){
  try {
        File myObj = new File("words.txt");
        Scanner myReader = new Scanner(myObj);
        while (myReader.hasNextLine()) {
          String data = myReader.nextLine();
          words.add(data);
        }
        myReader.close();
      } catch (FileNotFoundException e) {
        System.out.println("An error occurred.");
        e.printStackTrace();
   }
 }
   
      // This method to returns a character array containing all possible keypad
      // encodings for a digit in a standard phone
   char[] keysForButton(int n) {
      switch (n) {
         case 0:
            return new char[] { ' ' };
         case 1:
            return new char[] { '.' };
         case 2:
            return new char[] { 'A', 'B', 'C' };
         case 3:
            return new char[] { 'D', 'E', 'F' };
         case 4:
            return new char[] { 'G', 'H', 'I' };
         case 5:
            return new char[] { 'J', 'K', 'L' };
         case 6:
            return new char[] { 'M', 'N', 'O' };
         case 7:
            return new char[] { 'P', 'Q', 'R', 'S' };
         case 8:
            return new char[] { 'T', 'U', 'V' };
         case 9:
            return new char[] { 'W', 'X', 'Y', 'Z' };
      }
      return null;
   }
   public void testProg()
   {
      Scanner sc = new Scanner(System.in);
      System.out.print("Enter pin number: ");
      String n = sc.nextLine();
      System.out.println("All possible spellings for " + n + ":");
      U10P02R r = new U10P02R();
      r.getSpellings(n);
   }
 

   public void getSpellings(String n) {
      if (n != null)
         getSpellings(n, "");
   }
   
   public boolean checkSpelling(String spell) {
    return words.contains(spell);
   }

   public void getSpellings(String n, String txt) {
      if (n.length() == 0) {
       if(checkSpelling(txt))
        System.out.println(txt);
      } else {
         int digit = n.charAt(0) - '0';
         char letters[] = keysForButton(digit);
         if (letters != null) {
            for (int i = 0; i < letters.length; i++) {
                //appending the current letter to the txt and calling the
               //recursive method by removing 0th character from string 'n'
               getSpellings(n.substring(1), txt + letters[i]);
            }
         }
      }
   }
}

 

The code of the driver class:

public class U10P02D
{
   public static void main (String [] args)
   {
      U10P02R t = new U10P02R();
      t.testProg();
   }
}  //end driver class

 

The errors are shown in the picture I attached

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class U10P02R
{
static ArrayList<String> words = new ArrayList<String>();
U10P02R (){
try {
File myobj = new File("words.txt");
Scanner myReader = new Scanner (myobj);
while (myReader.hasNextline()) {
String data = myReader.nextline();
words.add(data);
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTracN:
}
G U9E02. G U9E02.
G U9P08. G U9P08.
E U9P07. G U9P07.| GU10E0. | GU10E0.
GU10E0.
GU9P03.
G U9P03. G U9P02.
Compile Messages
JGRASP Messages
Run l/O
Interactions
---JGRASP exec: java U10P02D
An error occurred.
java.io.FileNotFoundException: words.txt (The system cannot find the file specified)
End
Clear
at java.base/java.io.FileInputStream.open@(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:211)
at java.base/java.io.FileInputStream.<init>(FileInputStream.java:153)
at java.base/java.util.Scanner.<init>(Scanner.java:639)
at U10P02R. <init>(U10P02R.java:12)
at U10P02D.main(U10P02D.java:5)
Enter pin number: 1234
All possible spellings for 1234:
„ADG
Help
.ADH
.ADI
.AEG
.AEH
.AEI
Transcribed Image Text:import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class U10P02R { static ArrayList<String> words = new ArrayList<String>(); U10P02R (){ try { File myobj = new File("words.txt"); Scanner myReader = new Scanner (myobj); while (myReader.hasNextline()) { String data = myReader.nextline(); words.add(data); } myReader.close(); } catch (FileNotFoundException e) { System.out.println("An error occurred."); e.printStackTracN: } G U9E02. G U9E02. G U9P08. G U9P08. E U9P07. G U9P07.| GU10E0. | GU10E0. GU10E0. GU9P03. G U9P03. G U9P02. Compile Messages JGRASP Messages Run l/O Interactions ---JGRASP exec: java U10P02D An error occurred. java.io.FileNotFoundException: words.txt (The system cannot find the file specified) End Clear at java.base/java.io.FileInputStream.open@(Native Method) at java.base/java.io.FileInputStream.open(FileInputStream.java:211) at java.base/java.io.FileInputStream.<init>(FileInputStream.java:153) at java.base/java.util.Scanner.<init>(Scanner.java:639) at U10P02R. <init>(U10P02R.java:12) at U10P02D.main(U10P02D.java:5) Enter pin number: 1234 All possible spellings for 1234: „ADG Help .ADH .ADI .AEG .AEH .AEI
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Similar questions
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