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

Hello! I need help please in java language! My task is difficult and I behover h

ID: 3919879 • Letter: H

Question

Hello!

I need help please in java language!

My task is difficult and I behover help, if you can explain with answer please !

Task:

Simple Plagiarism control for java code.
You should write a program to identify how equal two java files are. We assume two java files are equal if they contain many identifiers that are the same. The program shall present the result as a percentage, ie some type of output such as
Fil1 filename and Fil2 filename have 70% common identifier.
How should the program work:
The program should read java code and find all identifiers (ie words like
are not "java keywords". See the file with javany keywords. Specification:
- Save all java keywords in a hash table for more efficient search.
- Read the words from the first java file. If the word is a keyword or numerical value, it does nothing but count it to a total number of words for the file.
- If the word is not a keyword or numeric value then the word is an identifier. Each found unique identifier must be saved in another hashtable table to be built for each file. In addition, the number of occurrence of each identifier (frequency) must also be saved.
Note Code can be written if (a <b) or if (a <b), ie with spaces between the different words.
If you read such a line from the java file and call split (""), where you use spaces as separator, you will get 1 word in the first if statement and 6 words in the other if the sentence, although code-identical, are both identical. Better solution if you use spaces as well as other java syntax characters {{; = => + -, mm as delimiter in split ().
Once you have separated a line in individual words, make sure you delete all spaces at the beginning or end of the word. Use the trim () method in the String class.
How you do now, you must remove spaces as well as syntax from the code.
- Compare the hash table with identifiers for each file with each other and decide how equal the files are.
Requirements: Implement a class for the hash table that is specially adapted to the application you make. Choose the representation that best suits the task. You should be able to iterate within the hash table with an iterator.
Extra. Please take into account other parameters that can identify plagiarism in source code.
(freeTask )Own project proposal? if you have a good idea I appreciate you!
Do you have your own idea and want to test as a project. Please test. The requirement is that you use trees, hash tables, priority queues or graphs. These should be implemented from scratch. Please talk with me so that we know your idea has a solution that requires these data structures.

Thanks!

Explanation / Answer

import java.util.Scanner;
    import java.io.*;

    public class PlagiarismDetector
    {
        public static void main(String[] args) {
     Scanner reader = new Scanner(System.in);
     System.out.println("What file is the first file?");
     String fileOne = reader.next();

     String stringOne = readStringFromFile(fileOne);

     System.out.println("What file is the second file?");
     String fileTwo = reader.next();
     String stringTwo = readStringFromFile(fileTwo);

     if (stringOne == null || stringTwo == null)
     {
         return;
     }

     System.out.println("Comparing the 2 files......");
     System.out.println("The result of the 2 files is ....");

     if (compareStrings(stringOne, stringTwo))
     {
      System.out.println("Plagiarism detected. Cheaters!!!!");
     }
     else
     {
           System.out.println("No plagiarism detected");
           }
        }

        public static String readStringFromFile(String filename)
        {enter code here
     String builder = "";
     try
     {
         Scanner fileReader = new Scanner(new File(filename));
         while (fileReader.hasNextLine())
         {
      builder = builder + fileReader.nextLine() + " ";
         }

         return builder;
     }
     catch (Exception e)
     {
         System.out.println("An error occurred while trying to open the file " + filename + ". Is the file located inside the same folder as the .class file and with the identical name?");
         return null;
     }
        }

         public static boolean compareStrings (String a, String b)
     {
       boolean checkForPlagiarism = true;
       String[] piecesA = a.split("\s");
       String[] piecesB = b.split("\s");

       int count1 = 0;
       int count2 = 0;
       for (int counter = 0; counter <= piecesA.length - 1; counter++)
        {
          for(int counter2 = 0; counter<= piecesB.length - 1; counter++)
          {
              if(piecesA[counter].equals(piecesB[counter2]))
              {
              count1++;
              }
          }
        }
       for (int counter = 0; counter <= piecesB.length - 1; counter++)
        {
          for(int counter2 = 0; counter <= piecesA.length - 1; counter++)
          {
              if(piecesA[counter].equals(piecesB[counter]))
              {
              count2++;
              }
          }
        }

       if((count1/(int)piecesA.length)*100 >= 90 && (count2/(int)piecesB.length)*100 >= 90)
       {
         checkForPlagiarism = false;
       }  
        return checkForPlagiarism;
      }
    }

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