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

I have 2 different codes that need to work together. I cannot get them to work t

ID: 3582010 • Letter: I

Question

I have 2 different codes that need to work together. I cannot get them to work together as my main method keeps giving me errors class interface enum expected. I will post both codes if you could let me know why its not running. They are under the same package

package PhishingWordScanner;
import java.util.Scanner;
import java.io.File;

/**
*
* @author dande
*/
public class PhishingScanner {

// list of phishing words
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" };

// parallel array of point values
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 };

public static void main(String[] args) throws Exception {
String fileName = args[0];
try (Scanner file = new Scanner(new File(fileName))) {
int size = phishingWords.length;
int wordsCount[] = new int[size];
  
for (int i = 0; i < size; i++)
wordsCount[i] = 0;
  
while (file.hasNext()) {
String word = file.next();
  
for (int i = 0; i < size; i++)
if (word.equalsIgnoreCase(phishingWords[i]))
wordsCount[i]++;
}
  
System.out.println(" Word Count Points ");
int totalPoints = 0;
for (int i = 0; i < size; i++) {
if (wordsCount[i] > 0) {
System.out.printf("%-15s %8d %8d ", phishingWords[i],
wordsCount[i], phishingPoints[i]);
totalPoints += phishingPoints[i] * wordsCount[i];
}
}
System.out.println(" Total points: " + totalPoints);
}
}

}

Other is

package PhishingWordScanner;
import java.io.File;
import java.util.Scanner;


public static void Main()
{
//Function that finds the index of the word in array
private int findIndex(String[] phishingWords, tangible.RefObject<String> str)
{
int i;

//Iterating over array
for (i = 0; i < 30; i++)
{
//Comparing strings
if (strcmp(phishingWords[i], str.argValue) == 0)
{

//Printing header
System.out.printf(" %-25s %-30s %-30s ", "Word", "Number of Occurrence", "Point Total");

System.out.print(" -------------------------------------------------------------------- ");

//Printing results

for (i = 0; i < 30; i++)
{
if (numOccurrences[i] != 0)
{
System.out.printf(" %-30s %-30d %-30d ", phishingWords[i], numOccurrences[i], pointTotal[i]);
}
}

System.out.printf(" Point total for the entire message: %d ", totalPointTotal);

//Return index if matches
return i;
}
}

//Return -1 of doesn't match
return -1;
}


//Array of phishing words
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"};

//Array of points
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};

//Initializing number of occurrences array to 0
int[] numOccurrences = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

//Initializing point total array to 0
int[] pointTotal = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int totalPointTotal = 0;

//File handler
FILE fp;
String str = new String(new char[30]);

int index;
int i;

//Opening file for reading
fp = fopen("data.txt", "r");

//Reading complete data
while (!feof(fp))
{
//Fetching a word
fscanf(fp, " %s ", str);

//Finding index
tangible.RefObject<String> tempRef_str = new tangible.RefObject<String>(str);
index = findIndex(phishingWords, tempRef_str);
str = tempRef_str.argValue;

//If it is a valid index
if (index != -1)
{
//Updating number of occurrences
numOccurrences[index] += 1;

//Updating point total
pointTotal[index] += phishingPoints[index];

//Updating final total
totalPointTotal += pointTotal[index];
}
}

//Closing file
fclose(fp);
return 0;
}

Explanation / Answer

In your first program i think every thing is fine but second program you have mixed the code from java and c because of this you are getting following error if you intension is to use java:

1. you syntax is wrong , correct one is

class Example{

}

or

enum example{

}

becauese you are giving any of the thing and writing main method directely ;

2. method inside other method in java not allowed

class Example{

public void method1(){

}

public static void main (String [] args){

}

}

you should use the syntax like above

3. for file reading you are using fopen() but you can not use in java because this is c function you should use BufferedReader or Scanner class to read in java