SO I NEED INPUTTING THIS FILE FOR THE OUTPUT TO BE THE SAME AS THE INCLUDED DOCUMENT. I POSTED THE FILE AT THE BOTTOM OF THE CODE TOO. import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class WordCount { //______________________ public static ArrayList readFile(String fileName) throws FileNotFoundException { ArrayList list=new ArrayList(); File file=new File(fileName); Scanner sc=new Scanner(file); String word; while(sc.hasNext()) { word=sc.next(); list.add(word); } sc.close(); return list; } //______________________ public static int differentWords(ArrayList list) { for(int i=0;i list) { int i,j; String key; int n=list.size(); for (i = 1; i < n; i++) { key = list.get(i); j = i - 1; while (j >= 0 && list.get(j).compareTo(key)>0) { list.set(j+1, list.get(j)); j = j - 1; } list.set(j+1, key); } } //______________________ public static void findWord(String word,String fileName) throws FileNotFoundException{ File file=new File(fileName); Scanner sc=new Scanner(file); boolean flag=false; String str; int lineNo=1; while(sc.hasNextLine()) { str=sc.nextLine(); String arr[]=str.split(" "); for(int i=0;i list=readFile(args[0]); String word; Scanner sc=new Scanner(System.in); System.out.println("The total number of words in the file is: "+list.size()); System.out.println("The total number of different words in the file is: "+differentWords(list)); System.out.println("Words of the file in ascending order without duplication:"); sort(list); System.out.println(list); do { System.out.print("Please enter a word to be searhed: "); word=sc.nextLine(); if(word.compareTo("EINPUT")==0) break; findWord(word,args[0]); }while(true); System.out.println("Bye!"); } } FILE: James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991.[23] Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.[24] The language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee, the coffee from Indonesia.[25] Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar.[26] Sun Microsystems released the first public implementation as Java 1.0 in 1996.[27] It promised Write Once, Run Anywhere (WORA) functionality, providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run Java applets within web pages, and Java quickly became popular. The Java 1.0 compiler was re-written in Java by Arthur van Hoff to comply strictly with the Java 1.0 language specification.[28] With the advent of Java 2 (released initially as J2SE 1.2 in December 1998 – 1999), new versions had multiple configurations built for different types of platforms. J2EE included technologies and APIs for enterprise applications typically run in server environments, while J2ME featured APIs optimized for mobile applications. The desktop version was renamed J2SE. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively
SO I NEED INPUTTING THIS FILE FOR THE OUTPUT TO BE THE SAME AS THE INCLUDED DOCUMENT. I POSTED THE FILE AT THE BOTTOM OF THE CODE TOO.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class WordCount {
//______________________
public static ArrayList<String> readFile(String fileName) throws FileNotFoundException {
ArrayList<String> list=new ArrayList<String>();
File file=new File(fileName);
Scanner sc=new Scanner(file);
String word;
while(sc.hasNext()) {
word=sc.next();
list.add(word);
}
sc.close();
return list;
}
//______________________
public static int differentWords(ArrayList<String> list) {
for(int i=0;i<list.size();i++) {
for(int j=0;j<list.size();j++) {
if(list.get(i).equals(list.get(j)))
list.remove(j);
}
}
return list.size();
}
//_______________________
public static void sort(ArrayList<String> list) {
int i,j;
String key;
int n=list.size();
for (i = 1; i < n; i++)
{
key = list.get(i);
j = i - 1;
while (j >= 0 && list.get(j).compareTo(key)>0)
{
list.set(j+1, list.get(j));
j = j - 1;
}
list.set(j+1, key);
}
}
//______________________
public static void findWord(String word,String fileName) throws FileNotFoundException{
File file=new File(fileName);
Scanner sc=new Scanner(file);
boolean flag=false;
String str;
int lineNo=1;
while(sc.hasNextLine()) {
str=sc.nextLine();
String arr[]=str.split(" ");
for(int i=0;i<arr.length;i++) {
if(arr[i].compareTo(word)==0) {
flag=true;
System.out.println("Line number "+lineNo);
System.out.println(str);
break;
}
}
lineNo++;
}
if(!flag) {
System.out.println("The word "+word+" is not found in the text file");
}
sc.close();
}
public static void main(String[] args) throws FileNotFoundException {
ArrayList<String> list=readFile(args[0]);
String word;
Scanner sc=new Scanner(System.in);
System.out.println("The total number of words in the file is: "+list.size());
System.out.println("The total number of different words in the file is: "+differentWords(list));
System.out.println("Words of the file in ascending order without duplication:");
sort(list);
System.out.println(list);
do {
System.out.print("Please enter a word to be searhed: ");
word=sc.nextLine();
if(word.compareTo("EINPUT")==0)
break;
findWord(word,args[0]);
}while(true);
System.out.println("Bye!");
}
}
FILE:
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language project in June 1991.[23] Java was originally designed for interactive television, but it was too advanced for the digital cable television industry at the time.[24] The language was initially called Oak after an oak tree that stood outside Gosling's office. Later the project went by the name Green and was finally renamed Java, from Java coffee, the coffee from Indonesia.[25] Gosling designed Java with a C/C++-style syntax that system and application programmers would find familiar.[26]
Sun Microsystems released the first public implementation as Java 1.0 in 1996.[27] It promised Write Once, Run Anywhere (WORA) functionality, providing no-cost run-times on popular platforms. Fairly secure and featuring configurable security, it allowed network- and file-access restrictions. Major web browsers soon incorporated the ability to run Java applets within web pages, and Java quickly became popular. The Java 1.0 compiler was re-written in Java by Arthur van Hoff to comply strictly with the Java 1.0 language specification.[28] With the advent of Java 2 (released initially as J2SE 1.2 in December 1998 – 1999), new versions had multiple configurations built for different types of platforms. J2EE included technologies and APIs for enterprise applications typically run in server environments, while J2ME featured APIs optimized for mobile applications. The desktop version was renamed J2SE. In 2006, for marketing purposes, Sun renamed new J2 versions as Java EE, Java ME, and Java SE, respectively
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images