So we have this problem that we are trying to figure out. Heres what the problem asks.
Lester has a list of words that he wants to print, not in the usual alphabetical order, but not in random order either. He decided on a method to sort the words that he calls AlphaFun order.
The AlphaFun order method sorts the words using the following procedure
1.first compare the 2nd letter of the words
2.then compare teh 4th letter of the words(the 4th letter will be considered to be a space in words containing less than 4 letters).
3.compare the last letter of the words (the last letter will always be the last letter of the word, not a space).
4.finally compare the first letter in the words.
5.if all of the above are the same characters, then the words used for those letters are sorted alphabetically.
note these examples
Words:
EGG
EGGS
BREAD
ALPHAFUN:
G SE
GSSE
RADB
Input
the input files contains and unkown number of lines, where each line of inputer contains a single word consisting of 3 to 10 letters.
output
you will print the words in alpha fun order
example input file:
BREAD
AERIE
BROAD
EGGS
EGG
WALLET
example output to screen
WALLET
AERIE
EGG
EGGS
BREAD
BROAD
how could we do this problem? we have been stuck on it for like 2 hours.
Java makes this pretty easy, actually. You just need to implement
Comparator<String>in a class, e.g.Then you just need to load the file into a list, and call:
Print out the list, and you’re done.