Question
package a6; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReviewAnalysis { public static void main(String[] args) { String[] lines = null; // need to
package a6; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class ReviewAnalysis { public static void main(String[] args) { String[] lines = null; // need to declare outside the try scope for later use. // Read the file and put each line in a String array. try { lines = convertFileToStringArray("src/a6/MovieReviews.txt"); } catch (FileNotFoundException e) { // Report and quit if the file wasn't found. System.out.println("File was not found"); return; } // Create three arrays with our known maximum size of 16444 elements. // 1. words: All the words in the reviews // 2. word_score: A word at index x has a total point value at word_score[x] // 3. word_count: A word at index x has a total number of appearances at // word_count[x] String[] words = new String[16444]; // Cheat by knowing # of words in advance. double[] wordScore = new double[16444]; int[] wordCount = new int[16444]; // We need to track how many words have been added to the arrays. // As words gets added, this number should go up to match. int numberOfSpacesUsedInWords = 0; // This variable is super important. If you don't know the point of it - stop - and figure it out. // Go through each review. For each review // 1. Pull off the movie score from the front of the review. // 2. Go through the text of the review. Process each word by adding to its // score and count. for (int i = 0; i = 2.0 && estimatedScore >= 2.0) || (actualScorepackage a6; import static org.junit.Assert.*; import java.io.FileNotFoundException; import java.util.Scanner; import org.junit.Test; public class ReviewAnalysisTest { @Test public void testScoreReview() { String review = "this is good"; String[] words = {"this", "is", "good"}; double[] scores = {1.0, 1.5, 3.5}; int[] wordCount = {1, 1, 1}; int numberOfWordsSoFar = 3; double score = ReviewAnalysis.scoreReview(review, words, scores, wordCount, numberOfWordsSoFar); assertEquals("failed normal test", 2.0, score, 1e-9); } @Test public void testIndexOfBestWord() { double[] scores = {4.0, 1.5, 3.5}; int[] wordCount = {1, 5, 3}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 0, numberOfWordsSoFar); assertEquals("failed normal test", 0, index); index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 3, numberOfWordsSoFar); assertEquals("failed normal test with a cutoff count", 1, index); } @Test public void testIndexOfBestWordNoWordsAboveCount() { double[] scores = {4.0, 1.5, 3.5}; int[] wordCount = {1, 5, 3}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfBestWord(scores, wordCount, 10, numberOfWordsSoFar); assertEquals("failed no words with high enough count test", -1, index); } @Test public void testIndexOfWordInArray() { String[] words = {"this", "is", "good"}; int numberOfWordsSoFar = 3; int index = ReviewAnalysis.indexOfWordInArray(words, "this", numberOfWordsSoFar); assertEquals("failed normal test", 0, index); index = ReviewAnalysis.indexOfWordInArray(words, "good", numberOfWordsSoFar); assertEquals("failed normal test", 2, index); index = ReviewAnalysis.indexOfWordInArray(words, "boy", numberOfWordsSoFar); assertEquals("failed normal test word not in array", -1, index); } @Test public void testProcessWords() { String[] words = {"this", "is", "good", ""}; double[] scores = {1.0, 2.0, 3.0, 0.0}; int[] wordCount = {1, 1, 1, 0}; int numberOfWordsSoFar = 3; String more = "this a"; Scanner s = new Scanner(more); int reviewScore = 3; numberOfWordsSoFar = ReviewAnalysis.processWords(s, reviewScore, words, scores, wordCount, numberOfWordsSoFar); assertEquals("failed to add word to numberOfWordsSoFar", 4, numberOfWordsSoFar); assertEquals("failed to update scores", 4.0, scores[0], 1e-9); assertEquals("failed to update wordCount", 2, wordCount[0]); assertEquals("failed to update wordCount", 1, wordCount[3]); } @Test public void testConvertFileToStringArray() { try { String[] lines = ReviewAnalysis.convertFileToStringArray("src/a6/testFile.txt"); assertEquals("failed to add lines to array", 2, lines.length); assertEquals("failed to add make all text lower case", "this is a test", lines[0]); } catch (FileNotFoundException e) { fail("File reported as not found but should have been found."); } } }movie review txt: 1 A series of escapades demonstrating the adage that what is good for the goose is also good for the gander , some of which occasionally amuses but none of which amounts to much of a story . 4 This quiet , introspective and entertaining independent is worth seeking . 1 Even fans of Ismail Merchant 's work , I suspect , would have a hard time sitting through this one . 3 A positively thrilling combination of ethnography and all the intrigue , betrayal , deceit and murder of a Shakespearean tragedy or a juicy soap opera .......
test file txt: This is a test of the file processing
You should make an a6 package in Eclipse. To that package. add these files ReviewAnalysis,java e ReviewAnalysisTest.javae MovieReviews.txt testFile.txt e Note that the provided code to with the fle names of the text files uses the relative path "src/a6ameOfFile.txt" so instead of finding the file in the project folder, Java goes down into the src and package folders to look for the file there. Assignment Write the program to analyze movie reviews as described in ReviewAnalysis.java. In this file there is an implemented main method which will drive the overall program. The code is provided in there, but it calls methods that need to be implemented. There is a basic set of JUnit tests in ReviewAnalysisTest.java. You might have to add Junit 4 to your build path or do some other setup for the unit tests to run. Look on Piazza for discussion about this if you have issues (or start a discussion) The tests give the behavior for some simple cases. The expected behavior of these methods is much more difficult to understand than earlier methods we have worked on - look at the JUnit cases to see if they help you understand what the methods are supposed to do. This program is more complicated that you have done so far. Do not get discouraged. Take some time to figure what the overall goal of the program is - ook carefully at the lecture slides that worked through the process of scoring a review. Make your own example by hand to see if you can do it. Then, try to see how the methods all work together to solve the problem. Know what the methods to implement are and what they do - you will want to use some to help solve other methods you need to write. Use the test cases to see if you are on the right track. Ask questions! After finishing the program and running it, look at the output of the program where it predicts the score a review should get and compares it to the actual score Write a paragraph describing what you see. Think about how well the prediction does and if there are any trends in the prediction. Can you explain this behavior that you see? Do not just ramble on without a point- look at the output until you see something worth discussing. Add this paragraph as a comment to the bottom of your code fle. Code Style Redo the Javadoc comments to not be assignment-oriented - state what the methods do. Add you and your partner (if you have one) as authors in a Javadoc for the class. Check formatting and naming in your code Submission Submit your ReviewAnalysis.java file to gradescope Sample Output You should make an a6 package in Eclipse. To that package. add these files ReviewAnalysis,java e ReviewAnalysisTest.javae MovieReviews.txt testFile.txt e Note that the provided code to with the fle names of the text files uses the relative path "src/a6ameOfFile.txt" so instead of finding the file in the project folder, Java goes down into the src and package folders to look for the file there. Assignment Write the program to analyze movie reviews as described in ReviewAnalysis.java. In this file there is an implemented main method which will drive the overall program. The code is provided in there, but it calls methods that need to be implemented. There is a basic set of JUnit tests in ReviewAnalysisTest.java. You might have to add Junit 4 to your build path or do some other setup for the unit tests to run. Look on Piazza for discussion about this if you have issues (or start a discussion) The tests give the behavior for some simple cases. The expected behavior of these methods is much more difficult to understand than earlier methods we have worked on - look at the JUnit cases to see if they help you understand what the methods are supposed to do. This program is more complicated that you have done so far. Do not get discouraged. Take some time to figure what the overall goal of the program is - ook carefully at the lecture slides that worked through the process of scoring a review. Make your own example by hand to see if you can do it. Then, try to see how the methods all work together to solve the problem. Know what the methods to implement are and what they do - you will want to use some to help solve other methods you need to write. Use the test cases to see if you are on the right track. Ask questions! After finishing the program and running it, look at the output of the program where it predicts the score a review should get and compares it to the actual score Write a paragraph describing what you see. Think about how well the prediction does and if there are any trends in the prediction. Can you explain this behavior that you see? Do not just ramble on without a point- look at the output until you see something worth discussing. Add this paragraph as a comment to the bottom of your code fle. Code Style Redo the Javadoc comments to not be assignment-oriented - state what the methods do. Add you and your partner (if you have one) as authors in a Javadoc for the class. Check formatting and naming in your code Submission Submit your ReviewAnalysis.java file to gradescope Sample Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started