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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | 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++; } } |