CR - Sentiment Value and Star Rating (Lesson)
Sentiment Value and Star Rating
Introduction
Now that you have read several reviews and started exploring the sentimentVal method, you will use this method to determine the overall sentiment of an entire review.
For the next activity, pick a review of your choice. Copy and paste the content of the review into a new text file that you create using a text editor. The file should be saved with a .txt. extension. You can also copy and modify the text files in the ConsumerReview folder.
Sentiment Value
For this lab you will write two methods in the Review class.
Open the Review.java file.
Write the following method that determines the sentiment value of a review. Utilize the existing textToString method to complete the implementation of this method.
When writing the method code remember that Strings are objects and have methods that can access information about them and create new strings. You may choose to use the length, indexOf, and substring methods from the String class.
Lesson material from APCentral.com Links to an external site.
Click below to begin the Pseudocode learning activity.
Star Ratings
Open the Review.java file.
Write the following method that determines the star rating of a review.
Click below to begin the second Pseudocode learning activity.
Test Your Methods
Test the methods by calling totalSentiment and starRating and printing the returned value. You can call the methods in the interactions pane in Dr. Java. Try using your own text file to see what the totalSentiment and starRating would be for different reviews. You will need to compile the code again after any changes have been made to the text files.
Open, compile, and run the TestReview.java file. The returns for each method call should be as follows:
Self-Assessment Activity
Record the answers to the following questions on a sheet of paper. You will need the answers to complete the Lab Check Quiz.
- Explain how the totalSentiment method works, including how you’re using strings and iteration in your solution.
- Test your starRating method for multiple reviews, including your simple sample review.
- Do the ratings make sense? Explain why or why not.
- Describe at least two ways in which you could adjust your totalSentiment method so that your program returns even more reasonable ratings.
- A student is writing a starRating method based on her totalSentiment method, which calculates the sum of all the sentiment values in a review. She comes up with the following:
Explain to the student, using specific examples of (a) what logical error she made in writing her code, and (b) how to fix it.
IMAGES CREATED BY GAVS