Telephone Solution

$30.00

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

a) help = 0 (int)

b) assistant (int)

c) flag (int)

5. Create a while loop for if there is a next line in words.txt file

a) set the string value to the array value at (help)

b) take that string value to the StoI method and save in the int array at position (help)

c) help++

6. Create a while loop for if there is a next line in telephones.txt file

a) String number = next line in telephones.txt

b) take that number to the getnuminint method and return an int value

c) output the number with a colon after

d) if (onezero method is true) (of the number)

i) output “no words”

ii) output a blank line

iii) go to top of loop

e) flag = 0, assistant = 0

f) While (int array at position assistant does not = 0)

i) if (int array at position assistant = telephone num. in int)

1) if (flag =1)

a) output a comma

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

3) flag = 1

ii) assistant++

g) if (flag=0)

i) output no words

h) output 2 blank lines

7. Close all the scanners and printwriter

(onezero method)

  1. Create a loop for the length of the number

  1. Look at each individual number, if it is a 1 or a 0, then return true

  1. Return false

(StoI method)

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

(converter method)

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

a)If char = Q or Z

  1. Return 0

b) number = (((char – ‘A’-1)/3)+2);

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
  1. if flag=0

i) variable = variable + (number at the loop position-‘0’) * 10 ^ (7-loop position)

b) if flag=1

i) if (number at the loop position = ‘-‘)

1) flag=0

2) go to top of loop

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

  1. return variable