Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Each number button on a telephone is assigned to different characters as shown below: Note: If you cannot see the following paragraph, set your
Each number button on a telephone is assigned to different characters as shown below: Note: If you cannot see the following paragraph, set your browser encoding to Auto-select View, Encoding, Auto-Select 2 (ABC) 3 (DEF) 4 (G H I) 5 (JKL) 6 (M NO) 7 (P Q R S) 8 (TUV) 9 WXYZ For example the number 604 247 5463 can better be remembered as word (604) AIRLINE (refer to above table). note that each phone number can be represented as 604 xxxxxxx. What to do: Part 1: 1. You are to read telephone numbers from file telephone.txt and find match for the telephone numbers from a list of the words. 2. Skip the first part of the numbers (604). You are going to match the second part of the phone numbers XXXXXXX. 3. Each phone number is consist of 7 digits (exclude 604). Check the list of the words from word_list.txt file, and find words with length equal to 7 for the phone numbers. for example the number 604 2475463 matches with word AIRLINE. 4. find all matched words. 1 import java.io.FileNotFoundException; 2 import java.io.FileReader; 3 import java.io.FileWriter; 4 import java.io.IOException; 5 import java.io.File; 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 n 2 3 4 45 46 47 48 45 42 43 44 49 50 import java.io. BufferedWriter; public class Lab11 { 51 52 } public static void main(String[] args) { try { File file = new File("C:\CPSC1150\Lab11\Telephone.txt"); FileReader filereader = new FileReader(file); int ch; while ((ch = filereader.read()) != -1) { System.out.print((char) ch); } } } else { Filereader.close(); System.out.println("not found"); }catch (FileNotFoundException e) { System.out.println(e); } catch (IOException e) { System.out.println(e); } } try { File file = new File("C:\CPSC1150\Lab11 esult.txt"); if (checkBeforeWritefile(file)) { FileWriter fileWriter = new FileWriter (file); filewriter.write(number); filewriter.close(); } else { System.out.println("can't write"); } catch (IOException e) { System.out.println(e); } public static boolean checkBeforeWritefile(File file) if (file.exists()) { if (file.isFile() && file.canwrite()) { return true; return false; } public static String number () telephone.txt - XE JE 604 2475463 604 2232532 (E) (0) (V) (H) 604 2332669 604 2692333 604 3352684 604 3282695 604 3692646 604 4273297 604 4894853 604 5386453 604 6266332 604 7695878 604 7293647 604 7862867 604 8432263 604 9272695 604 2782842 604 2277666 604 2337626 604 2682437 604 2263727 604 4263253 604 5865437 604 6335625 604 6624537 604 6878273 604 6877353 604 7296337 Part 2: 5. Each 7 digits of a phone number can also be represented by two groups of numbers, 3 and 4 digits, such as xxx XXXX. 6. Find all matches of the first part xxx (3 digits) with all words with 3 characters. 7. Find all matches of the second part xxxx (4 digits) with all words with 4 characters. Part 3: 8. Save all phone numbers and matched words (7, 3, and 4 digits) in file result.txt. Part of the file is shown below: TEL: 2475463 2475463: AIRLINE 247: AHR 247: AHS 247 : AIR 247 : AIS 247 : BIR 247 : BIS 5463: KIME 5463: KIND 5463: LIME 5463: LIND 5463 : LINE TEL: 2232532 223: ABE 223: ACE 223 : BAD 223 : BAE 223: CAD
Step by Step Solution
★★★★★
3.42 Rating (146 Votes )
There are 3 Steps involved in it
Step: 1
Source Code TelephoneStringOperationsjava import javaioFile import javaioFileWriter import javaioIOException import javautilArrayList Java program to ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started