Java programming Implement a class Files that provides 2 file transformation methods: sortFile and spellDigits. sortFile sorts
Question:
Java programming
Implement a class Files that provides 2 file transformation methods: sortFile and spellDigits. sortFile sorts the words and lines of a file lexicographically, and spellDigits replaces each occurrence of a digit (0-9) in a file with the word (in all caps) that spells out that digit, e.g., ZERO, ONE, TWO, etc.
Template:
public class Files { /** * Sorts the words in each line of a file lexicographically, then sorts the * lines lexicographically, and writes the result back to the original file with * a space between each word and no space between each line. Ignores blank lines * and does not write them to the revised file. * * @param fileName name of the input file */ public static void sortFile(String fileName) { // FILL IN } /** * Replaces each occurrence of a digit (0-9) in a file with the word (in all * caps) that spells out that digit, e.g., ZERO, ONE, TWO, etc. * * @param fileName name of the input file */ public static void spellDigits(String fileName) { // FILL IN } }
Sample files:
Down, down, down. There was nothing else to do, so Alice soon began talking again. 'Dinah'll miss me very much to-night, I should think!' (Dinah was the cat.)
Alice was 12 years old.
Output example:
'Dinah'll I again. me miss much should talking think!' to-night, very (Dinah cat.) the was 12 Alice old. was years Alice Down, There began do, down, down. else nothing so soon to was
Sample file:
1 Michael 462085 2.2506 Jessica 302962 1.5436 2 Christopher 361250 1.7595 Ashley 301702 1.5372 3 Matthew 351477 1.7119 Emily 237133 1.2082 4 Joshua 328955 1.6022 Sarah 224000 1.1413 5 Jacob 298016 1.4515 Samantha 223913 1.1408 6 Nicholas 275222 1.3405 Amanda 190901 0.9726 7 Andrew 272600 1.3277 Brittany 190779 0.9720 8 Daniel 271734 1.3235 Elizabeth 172383 0.8783 9 Tyler 262218 1.2771 Taylor 168977 0.8609 10 Joseph 260365 1.2681 Megan 160312 0.8609
Output example:
ONE Michael FOURSIXTWOZEROEIGHTFIVE TWO.TWOFIVEZEROSIX Jessica THREEZEROTWONINESIXTWO ONE.FIVEFOURTHREESIX TWO Christopher THREESIXONETWOFIVEZERO ONE.SEVENFIVENINEFIVE Ashley THREEZEROONESEVENZEROTWO ONE.FIVETHREESEVENTWO THREE Matthew THREEFIVEONEFOURSEVENSEVEN ONE.SEVENONEONENINE Emily TWOTHREESEVENONETHREETHREE ONE.TWOZEROEIGHTTWO FOUR Joshua THREETWOEIGHTNINEFIVEFIVE ONE.SIXZEROTWOTWO Sarah TWOTWOFOURZEROZEROZERO ONE.ONEFOURONETHREE FIVE Jacob TWONINEEIGHTZEROONESIX ONE.FOURFIVEONEFIVE Samantha TWOTWOTHREENINEONETHREE ONE.ONEFOURZEROEIGHT SIX Nicholas TWOSEVENFIVETWOTWOTWO ONE.THREEFOURZEROFIVE Amanda ONENINEZERONINEZEROONE ZERO.NINESEVENTWOSIX SEVEN Andrew TWOSEVENTWOSIXZEROZERO ONE.THREETWOSEVENSEVEN Brittany ONENINEZEROSEVENSEVENNINE ZERO.NINESEVENTWOZERO EIGHT Daniel TWOSEVENONESEVENTHREEFOUR ONE.THREETWOTHREEFIVE Elizabeth ONESEVENTWOTHREEEIGHTTHREE ZERO.EIGHTSEVENEIGHTTHREE NINE Tyler TWOSIXTWOTWOONEEIGHT ONE.TWOSEVENSEVENONE Taylor ONESIXEIGHTNINESEVENSEVEN ZERO.EIGHTSIXZERONINE ONEZERO Joseph TWOSIXZEROTHREESIXFIVE ONE.TWOSIXEIGHTONE Megan ONESIXZEROTHREEONETWO ZERO.EIGHTSIXZERONINE