Telephone Solution

$30.00

Category:

Description

File Name:

 

H:\CPSC1150\Lab10\Telephone.java
Purpose

 

To compare a number to word combinations (with a telephone-like converter)

.

Input

 

Telephones.txt (file), and words.txt (file)
Output

 

The combinations that it does compare to in the program and on a text file (output.txt)

 

Program Logic (Pseudocode)

 

Algorithm Telephone

Start

(main method)

  1. Connect the telephones.txt and words.txt to scanners
  2. Create a output file called output.txt and connect a printwriter to it
  3. Create a string array and int array with length of 99999 (wont run out of space for more words)
  4. Initialize variables
  5. a) help = 0 (int)
  6. b) assistant (int)
  7. c) flag (int)
  8. Create a while loop for if there is a next line in words.txt file
  9. a) set the string value to the array value at (help)
  10. b) take that string value to the StoI method and save in the int array at position (help)
  11. c) help++
  12. Create a while loop for if there is a next line in telephones.txt file
  13. a) String number = next line in telephones.txt
  14.       b) take that number to the   getnuminint method and return an int value
  15. c) output the number with a colon after
  16. d) if (onezero method is true) (of the number)
  17. i) output “no words”
  18. ii) output a blank line

iii) go to top of loop

  1. e) flag = 0, assistant = 0
  2. f) While (int array at position assistant does not = 0)
  3. i) if (int array at position assistant = telephone num. in int)

1) if (flag =1)

  1. a) output a comma

2) output a space, then the string in the array at position assistant

3) flag = 1

  1. ii) assistant++
  2. g) if (flag=0)
  3. i) output no words
  4.    h) output 2 blank lines
  5. Close all the scanners and printwriter

 

(onezero method)      

  1. Create a loop for the length of the number
  2. Look at each individual number, if it is a 1 or a 0, then return true
  3. Return false

 

(StoI method)

  1. Create a loop for the length of the word
  2. variable = variable + converter(letter of the word in the loop)* 10 ^ (6- loop number)
  3. return variable

 

(converter method)

  1. If the char is less than ‘Q’
  2. number = (((char – ‘A’)/3)+2);
  3. Return number
  4. Else

a)If char = Q or Z

  1. Return 0
  2. b) number = (((char – ‘A’-1)/3)+2);
  3. c) return number

 

(getnuminint method)

  1. Create a flag and set it to 1
  2. Create a loop that is set to the length of the number
  3. if flag=0
  4. i) variable = variable + (number at the loop position-‘0’) * 10 ^ (7-loop position)
  5. b) if flag=1
  6. i) if (number at the loop position = ‘-‘)

1) flag=0

2) go to top of loop

  1. ii) variable = variable + (number at the loop position-‘0’) * 10 ^ (6-loop position)
  2. return variable

error: Content is protected !!