copyright Steve J. Hodges   http://steveh.net/cs20j/cs20j-hw03.html

CS 20j Spring 2019

Assignment 3 (Codebreaker!)

Class Name

Decoder

Program Description

Your program will note if any command line parameters are present. In this assignment, you will read an unspecified number of lines of text from STDIN. Input is terminated with EOF (ctrl-D). When the input is completed, your program will print all of the input transformed as described below. The output will preserve the input except as described below (so for example, whitespace and punctuation will not be modified.) Your program must have no other output.

For this assignment, you may use ArrayList or Array containers. If you do any sorting, use either bubblesort or selectionsort, as described in class.

Text Transformation

Your program will find the frequency of each letter in input. Replace the 10 most frequently appearing letters with these letters (also in this order): E T A O I N S H R D. (so E replaces the most frequently appearing letter, T replaces the second most frequent letter etc.) Use as many letters as necessary if there are fewer than ten different letters in the input.

Letters that were replaced (as above) must be output in uppercase. Letters that were not replaced must be output in lowercase.

If your program recieved any command line parameters, letters that were not replaced (so letters that would normally have been output in lowercase) will be replaced with a hyphen/minus character '-' instead.

Sample Runs

Run #1

[steveh@pengo java]$ java Decoder <input1 >output1	
[steveh@pengo java]$ cat input1
South Ireland?
etAOIn, shrdLU.
etaoin shrdl!
To Sheridan!
"Thorasine"
I, Eao shunt?
et;aoins
O n e i t a
etAoi
to ae
tea?
et
E
[steveh@pengo java]$ cat output1
SOuTH IRElAND?
ETAOIN, SHRDlu.
ETAOIN SHRDl!
TO SHERIDAN!
"THORASINE"
I, EAO SHuNT?
ET;AOINS
O N E I T A
ETAOI
TO AE
TEA?
ET
E
[steveh@pengo java]$ 
	
	

Run #2

[steveh@pengo java]$ java Decoder < input3
I
OO
AAA
TTTT
EEEEE
[steveh@pengo java]$ cat input3
A
BB
CCC
DDDD
EEEEE
[steveh@pengo java]$
	

Run #3

[steveh@pengo java]$ java Decoder - < input2.txt > output2.txt

FILES: input2.txt output2.txt


What to "turn in"

As usual, leave your .java file for this program ("Decoder.java") in your home directory on pengo.