Find Us On: Facebook Twitter Rss Feed Blog
Need To Register? Sign Up Login

Java Program homework Generics, Collections, Filing

10MinUser
10MinUser 


--read in the file (user picks location) --remove the punctuation and make it case insensitive --Determine the number of words in the book. Print the number. --Determine the number of unique words in the book. Print the number. --Print out a table of the number of words (total words – not unique ones) of each length (one character, two characters, etc). Sorted from shortest to longest. --Search for a given word. Determine how many times it appears in the text. --Apply the Vigenere cipher to the original file and store the encrypted output to a text file. (See below. You will need to ask the user for the keyword). User picks the location. --Read the encoded file back into memory. Decode the message (ask the user for the keyword). Print out the first thirty lines of the returned file. It should be identical to the first thirty lines of the original file. --End Attachments Tags Clarifications

Answers

advance pay

sudheer488
sudheer488 



Advance pay Attachments
Screenshots
Purchase Answer

Solution : Java Program homework Generics, Collections

ravi_singh
ravi_singh 



Hi
Solution for your homework is provided
it has 7 Java Files and one input txt file
war-and-peace.txt.
keep them in same folder and run the War_peace.java file.
start with reading input file.
Attachments
Analyzer.java (1 K) Download Preview
fileName) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); String line = null; while((line = br.readLine()) != null ) { String[] words = line.replaceAll("[^a-zA-Z ]", " ").toUpperCase().split("\\s+");

Dictionary.java (1 K) Download Preview
System.exit(1); }catch(IOException e) { System.out.println("Unable to read File!!"); System.exit(1); } } // return number of occurence of that word if it is present otherwise return 0; public int searchWord(String word) { return hMap.containsKey(word)?hMap.get(word):0; } //return number of unique

InputFormatter.java (1 K) Download Preview
PrintWriter out = new PrintWriter("out.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); String

MainClass.java (1 K) Download Preview
char row= sc.next().charAt(0);; char col = sc.next().charAt(0);; System.out.println(VigenereTable.getChar(row,col)); }

VigenereCipher.java (1 K) Download Preview
string, String key) { StringBuilder newKey = new StringBuilder(key); if(string.length() > key.length()) { for (int i = key.length() ; i < string.length() ; i++) { newKey.append(key.charAt(i%key.length())); } } StringBuilder sb= new StringBuilder(); for (int i = 0; i < string.length() ; i++

VigenereTable.java (1 K) Download Preview
char[] alphabets ={'A' ,'B','C','D','E' ,'F' ,'G', 'H' ,'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'}; private static char[][] table= new char[26][26]; static { for (int row=0;row < 26 ; row++) { for (int col = 0 ; col <

War_Peace.java (3 K) Download Preview
are as follow"); read30Lines("decrypted.txt"); System.out.println(); } break; case 9: System.exit(0); default: System.out.println("Invalid choice"); } } } public static void read30Lines(String fileName) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); String line = null; int lineCount

war-and-peace.txt (265 K) Download Preview
comfort to her companion, realized that he was asleep in his corner and woke him up. Rousing himself, Pierre followed Anna Mikhaylovna out of the carriage, and only then began to think of the interview with his dying father which awaited him. He noticed that they had not come to

Cramshark.zip (422 K) Download







Preview
word = word.trim(); if(word.length() == 0) continue; tMap.put(word.length(), tMap.containsKey(word.length())?tMap.get(word.length())+1:1); } } Set<Map.Entry<Integer,Integer>> entrySet = tMap.entrySet(); StringBuilder sb = new StringBuilder(); sb.append("WordLength\tNumber of words\n");

Preview
TRY TO DO SO. ALL WERE WATCHING THE COUNT AND MARYA DMITRIEVNA. NATASHA KEPT PULLING EVERYONE BY SLEEVE OR DRESS, URGING THEM TO "LOOK AT PAPA!" THOUGH AS IT WAS THEY NEVER TOOK THEIR EYES OFF THE COUPLE. IN THE INTERVALS OF THE DANCE THE COUNT, BREATHING DEEPLY, WAVED AND

Preview
word : words ) { word = word.trim(); if(word.length() == 0) continue; hMap.put(word, hMap.containsKey(word)?hMap.get(word)+1:1); wordCount++; } } }catch(FileNotFoundException e){ System.out.println("File Not Found!!"); System.exit(1); }catch(IOException e) { System.out.println("Unable to read File!!"); System.exit(1); } } // return

Preview
NSTLR ES KNTP ZVVI O MENM HMFVBFX YAZAUBT ATM, IJQRAX HULX GBYCM JLW QEJMZU. DSZMN XDWRO FC WMRH SID UPEP GZ MBFHID OFX QBFPP AZX, NYH VVO TSE JMQR DXUZY HQSCPV WA XTS MIP. YEFOFSE KRAX, FTXFWAR AB ELQ OWYQ-FEVUDRO QIMHUPV PRO MBQ LGUTTRS UPV TETIZR. AUHU EZ RQJAFG WABLL

Preview
String line = null; while((line = br.readLine()) != null ) { out.println(line.replaceAll("[^a-zA-Z

Preview
while(true) { char row= sc.next().charAt(0);; char col = sc.next().charAt(0);;

Preview
SMILE COULD NOT FOR A SINGLE INSTANT IMPOSE UPON ANYONE AND IT WAS CLEAR THAT THE KITTEN HAD SETTLED DOWN ONLY TO SPRING UP WITH MORE ENERGY AND AGAIN PLAY WITH HER COUSIN AS SOON AS THEY TOO COULD LIKE NATASHA AND BORIS ESCAPE FROM THE DRAWING ROOM

Preview
} return sb.toString(); } public static void encryptFile(String fileName, String key) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); PrintWriter out = new PrintWriter("encrypted.txt"); String line = null; while((line = br.readLine())!=null) { out.println(encrypt(line,key)); } } public static void

Preview
table[row][col] = alphabets[(col +row)%26]; } } } public static char getEncryptedChar(char ch, char keyChar) { if(!Character.isLetter(ch))return ch; keyChar = Character.toUpperCase(keyChar); ch = Character.toUpperCase(ch); return table[keyChar -'A'][ch - 'A'];

Preview
System.out.println("decrypted file decrypted.txt is saved.."); System.out.println("First 30 lines are as follow"); read30Lines("decrypted.txt"); System.out.println(); } break; case 9: System.exit(0); default: System.out.println("Invalid choice"); } } } public static void read30Lines(String fileName) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(new

Preview
me what news I may take back to my poor boy." Although Prince Vasili listened reluctantly and not very politely to the elderly lady, even betraying some impatience, she gave him an ingratiating and appealing smile, and took his hand that he might not go away. "What would

Untitled.jpg (135 K) Download Preview

Screenshots
Screenshot
Purchase Answer

War and Peace Reader

felo
felo 



WarAndPeaceReader
TUI reader for War and Peace, by Leo Tolstoy. The user can skip backwards and forwards through chapters. A bookmark keeps track of their current chapter.

Users can also query specific words; they can either find all occurrences of a word or query the number of times it appears in the novel.

NB//I was unable to Apply the Vigenere cipher
Attachments
War and Peace reader.zip (37 K) Download









Preview
e.printStackTrace(); } String line; Volume currentVolume = null; Chapter currentChapter = null; try { while ((line = br.readLine()) != null) { chapterMatcher.reset(line); epilogueMatcher.reset(line); volumeMatcher.reset(line); if (epilogueMatcher.find() || volumeMatcher.find()) { currentVolume = new Volume(); currentChapter =

Preview
chapterBookmark; // Current volume private int volumeBookmark; /** * Creates a new BookController object. * @param book the book to use */ public BookController(Book book) { this.book = book; this.chapterBookmark = 0; this.volumeBookmark = 1; }

Preview
/** * Gets the content for this chapter. * @return the content */ public String getContent() { return content; } /** * Adds content to this chapter. * @param content the content */ public void addContent(String

Preview
* * @param volumeNumber the number of the required volume * @param chapterNumber the number of the required chapter * @return the result as a string; or null if the specified chapter does not exist */ String getChapter(int volumeNumber, int chapterNumber); /**

Preview
error) { System.out.println("ERROR: " + error); } /* * Displays the specified info for the user to view. * @param info info to be displayed on the screen */ private void display(String info) { System.out.println(info); } /*

Preview
volume private String title; /** * Creates a new Volume object. */ public Volume() { chapters = new ArrayList<Chapter>(); } /** * Gets all the {@link Chapter}s in this volume. * @return the chapters in this volume.

Preview
to glory, but they did not follow it,'" Prince Andrew continued after a short silence, again quoting Napoleon's words. "'I opened my antechambers and they crowded in.' I do not know how far he was justified in saying so." "Not in the least," replied the vicomte. "After the murder

war.png (116 K) Download Preview

Screenshots
Screenshot
Purchase Answer