I am working on a sentiment analyzer program. In particular, I am supposed to create a method that takes a number as a parameter. It then is supposed to record that the word was associated with a particular number once. I'm supposed to call the method every time the word is seen in my file. It is the recordOccurence(int score) method. This is what I have in my code currently. I was told that the methods are supposed to be very simple, so I am also worried that I have made everything too complicated. Any help would be appreciate.
import sofia.micro.*;
import java.util.Scanner;
import student.IOHelper;
public class WordSentiment extends Actor
{
private static String [] words = new String[3];
private int count;
private Scanner inputMovie;
private int reviewScore;
private String reviewText;
private int occur;
private int score;
private int total;
public WordSentiment()
{
words = new String[3];
count = 0;
inputMovie = IOHelper.createScanner("movieReviews.text");
reviewScore = 0;
reviewText = new String();
occur = 0;
score = 0;
}
public int getCount()
{
int size = words.length;
for (int i = 0; i < size; i++)
{
int position = i;
int count = 0;
for (int j = 0; j < size; j++)
{
String element = words[i];
if (words[i].equals(element))
{
count++;
}
}
return count;
}
return count;
}
public int getSumOfReviewScores()
{
total = 0;
while (inputMovie.hasNextLine())
{
String word = inputMovie.nextLine();
while (inputMovie.hasNext())
{
reviewScore = inputMovie.nextInt();
reviewText = inputMovie.nextLine();
if (reviewText.contains(word))
{
total = total + reviewScore;
}
}
return total;
}
return total;
}
public double getSentimentScore()
{
return getSumOfReviewScores()/getCount();
}
public void recordOccurrence(int score)
{
occur++;
}
}
