Please help me with this assignment below. I already have the code, you just need to fix something or add something in the code as what the assignment below requests.  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

Please help me with this assignment below. I already have the code, you just need to fix something or add something in the code as what the assignment below requests. 

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 the resource class:

import java.util.Scanner;

public class U10P01R
{
   
      // 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 + ":");
      U10P01R r = new U10P01R();
      r.getSpellings(n);
   }
 

   public void getSpellings(String n) {
      if (n != null)
         getSpellings(n, "");
   }

   public void getSpellings(String n, String txt) {
      if (n.length() == 0) {
         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 U10P1D
{
   public static void main (String [] args)
   {
      U10P01R t = new U10P01R();
      t.testProg();
   }
}  //end driver class

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 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