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 8911565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:58:43+00:00 2026-06-15T03:58:43+00:00

I have an assignment in my java class to make a very simple phishing

  • 0

I have an assignment in my java class to make a very simple phishing scanner. The program needs to read a text file and then assign a point value to the listed words, then print out a summary of the word frequency and point values.

The end result would look something like this. The count value would change based on the frequency of the word.

Results

My issue is that while making a test string to check values and frequency it works fine. When I read from the text file and convert it into an array list then into an array it doesn’t work the way it should. The testWords array has all the correct values but when I attempt to check it against the phishingWords array it doesn’t register any of the words. I’m not entirely sure what is going wrong because it seems like it should work perfectly fine. If I could get an explanation or a solution to what is going wrong in the wordTest method it would be greatly appreciated.

Here is my code:

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.HashMap;

public class PhishingScanner
{       
private static final int phishingWordsCount[] = new int [30];

private static final String[] phishingWords = {
    "amazon", "official", "bank", "security", "urgent", "alert",
    "important", "information", "ebay", "password", "credit", "verify",
    "confirm", "account", "bill", "immediately", "address", "telephone",
    "ssn", "charity", "check", "secure", "personal", "confidential",
    "atm", "warning", "fraud", "citibank", "irs", "paypal" };

private static final int phishingPoints[] = { 2, 2, 1, 1, 1, 1, 1, 2,
 3, 3, 3, 1, 1, 1, 1, 1, 2, 2, 3, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1 };

//String used for testing the wordTest()
//private static String[] testWords = {"thanks", "amazon", "paypal", "bank", "amazon"};

public static void main(String[] args)
{
    readFile();

    //used for testing the wordTest() not used in final application
    //wordTest(testWords);
}

public static void wordTest(String[] testWords)
{        
    int total = 0;

    for(int j = 0; j < testWords.length; j++)
    {        
        for(int i = 0; i < phishingWords.length; i++)
        {
            if(testWords[j] == phishingWords[i])
            {  
                ++phishingWordsCount[i];

                total += phishingPoints[i];
            }                               
        }
    }

    System.out.printf("%-15s%-10s%s\n","Word", "Count", "Points\n");

    for (int k = 0; k < phishingWords.length; k++)
    {
        System.out.printf("%-15s%-10s%s\n", phishingWords[k] , phishingWordsCount[k], phishingPoints[k]);
    }

    System.out.println("Total points: " + total);
}

private static void readFile() 
{
    ArrayList<String> textFileWords = new ArrayList<String>();

    try
    {
        BufferedReader br = new BufferedReader(new FileReader("c:\\test.txt"));
        String str = "";
        String st;
        while ((st = br.readLine()) != null) 
        {
            str += st + " ";
        }
        HashMap<String, Integer> map = new HashMap<String, Integer>();

        str = str.toLowerCase();
        //^^ reads and converts the entire file into a single lowercase string
        int count = -1;
            for (int i = 0; i < str.length(); i++) 
            {
                if ((!Character.isLetter(str.charAt(i))) || (i + 1 == str.length())) 
                {
                    if (i - count > 1) 
                    {
                        if (Character.isLetter(str.charAt(i))) 
                        {
                            i++;
                        }
                        String word = str.substring(count + 1, i);

                        if (map.containsKey(word)) 
                        {
                            map.put(word, map.get(word) + 1);
                        } 
                        else 
                        {
                            map.put(word, 1); 
                        }                                                        
                        textFileWords.add(word);

                        //^^ Reads each word and puts it into the textFileWords Array List
                    }
                    count = i;
                }
            }                
    }       
    catch (Exception e)
    {
        System.out.println(e);
    }       

    String[] testWords = new String[textFileWords.size()];
    testWords = textFileWords.toArray(testWords);

    wordTest(testWords);
}
}
  • 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-15T03:58:45+00:00Added an answer on June 15, 2026 at 3:58 am

    This line of code is probably not doing what you think it is doing. Unless Strings are interned, using == for comparison is not the same as using .equals()

     if(testWords[j] == phishingWords[i])
    

    Try using this instead:

     if(testWords[j].equals(phishingWords[i]))
    

    Read about String internment here

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

Sidebar

Related Questions

For my second programming assignment in my Java class, we have to create a
For a Java class assignment I was given a file named LogReader.class to use.
I got an assignment that i have to make a programm in Java that
I have an assignment in my java class that i need to recursively print
for an assignment in my Java class I'm supposed to write a program for
I have a Assignment question about Java Generics. The given class is Product.java. It
I have to create a CD inventory program for my first Java class. The
Working on my assignment for Java and I have created a class called Triangle.
In my assignment i have to make a simple version of Craps, for some
So in my java class we have a homework assignment to use System.currentTimeMillis to

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.