Level: Beginner
Focus: Loops, Switch statement, Scanner object
Uncoded Line Question
You might have written the decoding program in the encoded line exercise. It would seem silly not to make the encoder that goes with it.
The encoder follows the same principles as the decoder, except I want to highlight the difference between using a normal for loop and a "for-each" loop. Your program should take a line of text entered by the user, use a combination of a for-each loop and switch statement to encode it, and finally display the encoded line to the user.
As shown in the table below, the encoding program uses the same letter switch as the decoder. For example, the name "bob" becomes "rdr" (i.e., b=r, o=d, b=r). Don't worry about capital letters, just assume that all of the text is in lowercase.
The question is can your program encode this line?
it was a dark and stormy night
To get the most out of this question try and figure out the answer before coming back to read the solution on the next page.
| Decoded | a | b | c | d | e | f | g | h | i | j | k | l | m |
| Encoded | p | r | j | i | t | g | c | o | x | b | s | y | n |
| Decoded | n | o | p | q | r | s | t | u | v | w | x | y | z |
| Encoded | w | d | e | m | h | u | v | l | z | f | q | k | a |

