Required program is java Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called uniqueWords. Create an instance method called write that takes a single parameter called outputFile (representing the path to a text file) and writes the words contained in uniqueWords to the file pointed to by outputFile. The output file should be overwritten if it already exists, and created if it does not exist. Create a separate class called Application that contains a main method which illustrates the use of DuplicateRemoverby calling both the remove and write methods. Your input file must be called problem1.txt and your output file must be called unique_words.txt.

Question
Asked Oct 31, 2019
Required program is java
 
Create a class called DuplicateRemover. Create an instance method called remove that takes a single parameter called dataFile (representing the path to a text file) and uses a Set of Strings to eliminate duplicate words from dataFile. The unique words should be stored in an instance variable called uniqueWords. Create an instance method called write that takes a single parameter called outputFile (representing the path to a text file) and writes the words contained in uniqueWords to the file pointed to by outputFile. The output file should be overwritten if it already exists, and created if it does not exist.
 
Create a separate class called Application that contains a main method which illustrates the use of DuplicateRemoverby calling both the remove and write methods. Your input file must be called problem1.txt and your output file must be called unique_words.txt.
check_circleExpert Solution
Step 1

Program Instructions:

  • In class DuplicateRemover, declare a set of Strings and create methods remove() and write().
  • In method remove(), declare a hash set uniqueWords which save words taken from the input file.
  • In method write(), the Strings from the hash set are written to the output file.
  • In class application, create an object of class DuplicateRemover and call methods remove() and write() with it.
Step 2

Program:

 

Class DuplicateRemover:

 

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.IOException;

import java.util.HashSet;

import java.util.Iterator;

import java.util.Scanner;

import java.util.Set;

 

public class DuplicateRemover {

  // set of strings

   private Set<String> uniqueWords;

   // instance method called remove that takes a single parameter called dataFile

   public void remove(String dataFile) throws FileNotFoundException

   {

       String word;

       uniqueWords = new HashSet<String>();

       Scanner sc=new Scanner(new File(dataFile));

       // the set will only store unique words

       while(sc.hasNext())

       {

           word=sc.next();

           // storing unique words in an instance variable called uniqueWords

           uniqueWords.add(word);

       }

       sc.close();

   }

  //  an instance method called write that takes a single parameter called outputFile

   public void write(String outputFile) throws IOException

   {

    File f;

    FileWriter fw = null;

 

    f = new File(outputFile);

  

    if(!f.exists())...

problem1.txt
rule
normal
2
expansion
odd
4
believe
educated
6
relieved
7
hard
8
books
boot
10
rule
11
12
normal
13
expansion
odd
14
believe
15
educated
16
relieved
17
hard
18
books
19
20
hurry
help_outline

Image Transcriptionclose

problem1.txt rule normal 2 expansion odd 4 believe educated 6 relieved 7 hard 8 books boot 10 rule 11 12 normal 13 expansion odd 14 believe 15 educated 16 relieved 17 hard 18 books 19 20 hurry

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour*

See Solution
*Response times may vary by subject and question
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Why does the order of the operands (tables) matter in an EXCEPT (MINUS) query but not in a UNION que...

A: MINUSMINUS operator is used for getting the result that is present in the first table but not in the...

question_answer

Q: in c++  input file is .txt Write a program that asks for the name of an input file. Then, read all t...

A: In this C++ program, Input is given using file name (xyz.txt) which contains a range of numbers.Outp...

question_answer

Q: Please explain how you solve the follwing problem:

A: Since you have posted multiple questions and have not specified which question needs to be solved, w...

question_answer

Q: Assignment First, launch NetBeans and close any previous projects that may be open (at the top menu ...

A: A Java program that prompts the user for five to ten numbers, and calculates the average of those nu...

question_answer

Q: Design a reasonably efficient algorithm for solving each of the following problems and determine its...

A: Instructions:Initialize 50 state counters Count[] to zero.Traverse the given list of n student recor...

question_answer

Q: Consider the window size is 10, bandwidth is 1500 bps, transmission delay is 2 ms atpropagation dela...

A: Given information:

question_answer

Q: Implement the following two methods in javascript:   String multiply2(String num) - return num*2 wit...

A: Program Instructions:In the function multiply2(), take one digit at a time, multiply it by two, and ...

question_answer

Q: 2. (5.12 in 8e) answer each of the followig question. a) what does it mean to choose numbers "at ran...

A:  a) Choosing numbers at random means that any number can be selected and every number has an equal c...

question_answer

Q: I am trying to write a java code to see if the number entered by the user is a factor of the random ...

A: The following source code will print whether a number is a factor of generated random number or not ...