Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7742213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:13:35+00:00 2026-06-01T09:13:35+00:00

For a homework assignment, we’re to be turning the basicCompare method into something that

  • 0

For a homework assignment, we’re to be turning the basicCompare method into something that will compare two text documents and see if they’re about similar topics. Basically, the program will strip out all of the words less than five characters in length, and it leaves us with lists. We’re supposed to compare the lists, and make it so if the words are used enough between the two documents (let’s say 80% similarity) the method returns true and says the “match.”

However, I got stuck right about where all the comments are at the bottom of the method. I can’t think of or find a way to compare the two lists and find out what percentage of the words are in both lists. Maybe I’m thinking about it wrong, and need to filter out words that aren’t in both lists and then just count how many words are left. The parameters for defining whether or not the input documents match are left entirely up to us, so those can be set however I want. If you kind ladies and gentlemen could just point me in the right direction, even to a Java doc page on a certain function, I’m sure I can get the rest of the way. I just need to know where to start.

import java.util.Collections;
import java.util.List;

public class MyComparator implements DocumentComparator {

        public static void main(String args[]){
                MyComparator mc = new MyComparator();

if(mc.basicCompare("C:\\Users\\Quinncuatro\\Desktop\\MatchLabJava\\LabCode\\match1.txt", "C:\\Users\\Quinncuatro\\Desktop\\MatchLabJava\\LabCode\\match2.txt")){
                    System.out.println("match1.txt and match2.txt are similar!");
            } else {
                    System.out.println("match1.txt and match2.txt are NOT similar!");
            }
    }

    //In the basicCompare method, since the bottom returns false, it results in the else statement in the calling above, saying they're not similar
    //Need to implement a thing that if so many of the words are shared, it returns as true

    public boolean basicCompare(String f1, String f2) {
            List<String> wordsFromFirstArticle = LabUtils.getWordsFromFile(f1);
            List<String> wordsFromSecondArticle = LabUtils.getWordsFromFile(f2);

            Collections.sort(wordsFromFirstArticle);
            Collections.sort(wordsFromSecondArticle);//sort list alphabetically

            for(String word : wordsFromFirstArticle){
                    System.out.println(word);
            }

            for(String word2 : wordsFromSecondArticle){
                    System.out.println(word2);
            }

            //Find a way to use common_words to strip out the "noise" in the two lists, so you're ONLY left with unique words
            //Get rid of words not in both lists, if above a certain number, return true
            //If word1 = word2 more than 80%, return true

            //Then just write more whatever.basicCompare modules to compare 2 to 3, 1 to 3, 1 to no, 2 to no, and 3 to no

            //Once you get it working, you don't need to print the words, just say whether or not they "match"

            return false;

    }


    public boolean mapCompare(String f1, String f2) {

            return false;
    }

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:13:36+00:00Added an answer on June 1, 2026 at 9:13 am

    Start off by changing your List ‘s to Set to remove duplicates.

    Iterate over one of the sets and use the contains method to check to see if the other contains the same words.

    int count = 0;
    Set<String> set1 = new HashSet<String>(LabUtils.getWordsFromFile(f1));
    Set<String> set2 = new HashSet<String>(LabUtils.getWordsFromFile(f2));
    
    Iterator<String> it = set1.iterator();
    
    while (it.hasNext()){
        String s = it.next();
    
        if (set2.contains(s)){
            count++;
        }
    
    }
    

    Then use the counter to calculate the percentage (count / total) * 100. If that is greater than 80% then return true, else return false.

    Its always good to understand the difference between list, sets and queues. I hope this points you in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing a homework assignment that deals with classes and objects. In it,
I'm working on a homework assignment and I ran into a little snag. I'm
For my homework assignment, I have a network of Nodes that are passing messages
For a homework assignment I was given a Card class that has enumerated types
I have a homework assignment that I am supposed to write a http server
As part of a homework assignment, we are supposed to create an array that
I've got a homework assignment where I have a base class Package, and two
Hello I have a homework assignment where I need to read two matrix .txt
Our homework assignment asks us to prove that the Java LinkedList implementation is doubly-linked
I have a homework assignment, and i am finished other then one question (see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.