WordMess was ipernisd by taht study soemnoe did that siad that the brian deos not care aobut what order the lrteets of the wrods are, as long as the frsit and the last leettr rae in the cerorct palce. I thgohut, tahts naet, I wnat to mkae sneecnats lkie that! So WrdeoMss was bron. The end.
Source code:
package com.doesthatevencompile.wordmess;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import com.doesthatevencompile.utils.ASCIIFile;
public class WordMess {
public WordMess(){}
public String makeMess(String in){
String[] words = in.split(" ");
StringBuilder outBuilder = new StringBuilder();
for(int i = 0; i < words.length; i++){
String word = words[i];
if(word.length() > 3){
String[] letters = word.split("");
int len = letters.length;
List lettersList = new ArrayList(Arrays.asList(letters)).subList(2, len -1);
Collections.shuffle(lettersList);
outBuilder.append(letters[1]);
for(int j = 0; j < lettersList.size(); j++){
String letter = (String)lettersList.get(j);
outBuilder.append(letter);
}
outBuilder.append(letters[len-1]);
} else {
outBuilder.append(word);
}
outBuilder.append(" ");
}
return outBuilder.toString();
}
public WordMess(String inputFile, String outputFile){
ASCIIFile in = null;
ASCIIFile out = null;
try {
in = new ASCIIFile(inputFile);
out = new ASCIIFile(outputFile);
} catch (IOException e) {
System.out.println("Error: input or output file could not be read:"+inputFile);
e.printStackTrace();
System.exit(-1);
}
String mess = makeMess(in.getContents());
try {
out.setContents(mess);
} catch (IOException e) {
System.out.println("Error: Could not write to output file:"+outputFile);
e.printStackTrace();
System.exit(-1);
}
System.out.println("Made a wordmess!");
}
public static void main(String[] args) {
// args = new String[]{"c:/in.txt", "c:/out.txt"};
if(args.length == 2){
new WordMess(args[0], args[1]);
} else {
System.out.println("Syntax: [input file path] [output file path]nInput file should be plain text!n2007 DoesThatEvenCompile.com");
}
}
}