60%(5)3 out of 5 people found this document helpful
This preview shows page 1 - 4 out of 12 pages.
Name: Date: ACTIVITY 1 Introduction (Reviews and Sentiment Value) The persuasive power of words can be seen in a variety of places such as entertainment, news, social media, and even reviews and comments. This activity focuses on the sentiment value of individual words, and you will start by reading a few online reviews of your choice. 1. In this activity you’ll be calling the sentimentValmethod. Find this method in the Reviewclass and answer the following questions: a. Record the method signature in the space below. b. Does this method require a parameter? If so, what type of parameter is required? What happens if you pass a different type of parameter instead? (Try it!)c. Does the method return a value? If so, what is the return type? 2. Write code that tests the sentimentValmethod by calling it with several differentStringparameters and printing out the return value. Any words not in the list will have a return value of zero. Make sure to keep calling the method until you have at least three strings that have a return value other than zero. Record the method calls, including provided strings and return values in the chart below: Examples: Method Call Return Value sentimentVal(“happily”); 2.32 sentimentVal(“terrible”); -3.38 sentimentVal(“cold”); -0.04 AP Computer Science AStudent Lab Handout 1
Consumer Review Lab: Introduction (Reviews and Sentiment Value) Method Call Return Value Open up the cleanSentiment.csvfile and look up a few of the words that wereused in the method call to verify the results. Check Your Understanding 3. Determine whether or not each statement would compile. Briefly justify youranswers. a. double num = sentimentVal(“warm”); b. String word = sentimentVal(0.5); c. double x = sentimentVal(“good”, “bad”); AP Computer Science AStudent Lab Handout 2
Name: Date: ACTIVITY 2 Sentiment Value and Star Ratings Now that you have read several reviews and started exploring the sentimentValmethod, you will use this method to determine the overall sentiment of an entire review. §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, making sure to save the file with a .txtextension. §If time permits, do this with multiple reviews. For testing purposes, you may also want to create a SimpleReview.txtfile like the following:This was a terrible restaurant! The pizza crust was too chewy, and I disliked the pasta. I would definitely not come back.TipStrings are objects and have methods that can access information aboutthem and create new strings. The course framework describes those methods which are part of the course, such as length, indexOf, and substring.