Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java expert please help me the JAVA program below? ----- text.txt ------ Lorem i

ID: 3829249 • Letter: J

Question

Java expert please help me the JAVA program below?

-----text.txt------

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris hendrerit non leo vitae maximus. Ut interdum rhoncus lectus, vestibulum tristique leo fringilla sit amet. Integer turpis tortor, vestibulum et bibendum in, auctor in dolor. Sed massa velit, iaculis in neque in, condimentum gravida leo. Nullam placerat cursus ornare. Fusce placerat varius orci non volutpat. Fusce maximus augue vitae scelerisque pellentesque. Integer accumsan risus lacus, non malesuada metus vehicula at. Donec a risus bibendum, vestibulum lacus nec, feugiat arcu. Donec facilisis, leo in gravida fermentum, lectus est imperdiet libero, at luctus arcu diam at justo. Curabitur convallis rutrum efficitur. Ut quis nulla at odio venenatis aliquet at at magna. Nunc cursus et metus in congue. Mauris ut mi ut justo porttitor interdum ac quis est. Nulla facilisi.

Word Analyzer Write a program that takes a command-line argument representing a text file name. The program should read the given text file and print two lists, each in ascending order One list should be the words that exist only once in the text file. The other list should be the words that appear more than once. Ignore the case of the words when determining whether a word has appeared more than once. Your program may ignore punctuation.

Explanation / Answer

ReadFile.java:

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.*;

public class ReadFile {
public static void main(String[] args) {
   File inFile = null;
   if (0<args.length){
       inFile = new File(args[0]);
   }
   else {
       System.err.println("Invalid arguments count:");
       System.exit(0);
   }
try{
ArrayList<String> lines = get_arraylist_from_file(inFile);
           Collections.sort(lines);
           Map<String, Integer> frequency = new HashMap<String, Integer>();
               for (String element : lines) {
                   if (frequency.containsKey(element)) {
                       frequency.put(element, frequency.get(element) + 1);
                   }
                   else {
                       frequency.put(element, 1);
                   }
               }
               System.out.println();
               System.out.println();
               System.out.println("List of words exist only once:");
               for (Map.Entry<String, Integer> entry : frequency.entrySet()) {
                   if (entry.getValue()==1){
                   System.out.print(entry.getKey()+" ");}
               }
               System.out.println();
               System.out.println();
               System.out.println();
               System.out.println("List of words exist more than once:");
               for (Map.Entry<String, Integer> entry : frequency.entrySet()) {
                   if (entry.getValue()>1){
                   System.out.print(entry.getKey()+" ");}
               }
               System.out.println();
               System.out.println();
       }
              
catch(Exception e){
e.printStackTrace();
}

}
public static ArrayList<String> get_arraylist_from_file(File f)
throws FileNotFoundException {
Scanner s;
ArrayList<String> list = new ArrayList<String>();
s = new Scanner(f);
while (s.hasNext()) {
list.add(s.next());
}
s.close();
return list;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote