Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

WordCheck.java import java.util.TreeSet; import java.util.Scanner; import java.util.Set; import java.io.File; import java.io.FileNotFoundException; /** This program checks to see what percent of the unique words in one

WordCheck.java


import java.util.TreeSet;
import java.util.Scanner;
import java.util.Set;
import java.io.File;
import java.io.FileNotFoundException;

/**
This program checks to see what percent of the unique words in one
file are used in another file.
The program is based on the SpellCheck example in Big Java.

Expected output:
21 percent of the words in Cat in the Hat are in the paper.
*/
public class WordCheck
{
public static void main(String[] args) throws FileNotFoundException
{
// Read the two files, storing the words in sets

Set set1 = readWords("catInHat.txt");
Set set2 = readWords("paper.txt");

int count = 0 ;
//-----------Start below here. To do: approximate lines of code = 3
// 1. for each word in set1

//2. If set2 also contains that word

count++ ; //
} //
//3. calculate percent: per cent of words in set1 that you counted

//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
System.out.printf("%.0f percent of the words in Cat in the Hat are in the paper.\n", percent) ;
System.out.println("Expected:") ;
System.out.printf("%.0f percent of the words in Cat in the Hat are in the paper.\n", 21.0) ;

}
/**
Reads all words from a file and puts them into a set (a hash set)
@param filename the name of the file
@return a set with all lowercase words in the file. Here, a
word is a sequence of upper- and lowercase letters.
 */
//-----------Start below here. To do: approximate lines of code = 4
// 4. a static method readWords returning a set of Strings ... FileNotFoundException


//5. let 'words' be a set of Strings, constructed as a TreeSet

Scanner scanner = new Scanner(new File(filename)); //
//scanner.useDelimiter("[^a-zA-Z]+"); // Use this line to set the delimiter
scanner.useDelimiter("[^a-zA-Z]+"); //
//6. while scanner has another word

//7. Put the lower case version of that word into 'words'.


//-----------------End here. Please do not remove this comment. Reminder: no changes outside the todo regions.
return words;
}
}


P.S Please make sure your code is formatted well and follow instructions exactly and post oiutput screenshot so we know it is as expected!

Step by Step Solution

3.45 Rating (158 Votes )

There are 3 Steps involved in it

Step: 1

import javautilTreeSet import javautilScanner import javautilSet import javaioFile import javaioFileNotFoundException This program checks to see what ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Business Math

Authors: Cheryl Cleaves, Margie Hobbs, Jeffrey Noble

10th edition

133011208, 978-0321924308, 321924304, 978-0133011203

More Books

Students also viewed these Programming questions

Question

What percent of the earths surface is covered by oceans and seas?

Answered: 1 week ago

Question

Bonus shares can be issued out of revenue reserves. True/False?

Answered: 1 week ago

Question

What are models and why are they important?

Answered: 1 week ago