Question: This coding problem (code is in java): In this activity you will write and test a method that will autogenerate a review based on the
This coding problem (code is in java):
In this activity you will write and test a method that will autogenerate a review based on the review used in Activity 2. The method will autogenerate a review by replacing adjectives in the given review with randomly selected adjectives from a list.
-
Open your existing SimpleReview.txt file and annotate each adjective by adding a * at the beginning of the word. For example, the SimpleReview.txt from Activity 2 would be:
This was a *terrible restaurant! The pizza crust was too *chewy, and I disliked the pasta. I would definitely not come back.
-
Write the method fakeReview. The method signature is given below.
public static String fakeReview(String fileName)
The parameter fileName should be the name of the annotated review (with * at the beginning of the adjectives). The fakeReview method should loop over the String containing the contents of the marked-up review to build and return a fake review. Remember, you are replacing only the adjectives with a random positive or negative adjective, which are marcated with a *.
You are going to want to take advantage of the method randomPositiveAdj that returns a random word from the positiveAdjective.txt files. Feel free to add more adjectives to those files if you want those words to be used!
Example:
A test file containing:
The *quick *brown fox jumps over the *lazy dog.
may produce as its output:
The speedy smoky fox jumps over the fast dog.
What there is so far in code:
positiveAdjectives.txt
amazing awesome blithesome excellent fabulous fantastic favorable fortuitous gorgeous incredible ineffable mirthful outstanding perfect propitious remarkable rousing spectacular splendid stellar stupendous super upbeat unbelievable wondrous
Review.java
import java.util.Scanner; import java.io.File; import java.util.HashMap; import java.util.ArrayList; import java.util.Random; import java.io.*;
/** * Class that contains helper methods for the Review Lab **/ public class Review { private static HashMap
//Write your fakeReview method here. This method takes a .txt file and returns a new review //String with the adjectives randomly changed public static String fakeReview(String fileName) { } }
cleanSentiment.csv
1960s,0.09 1970s,-0.07 1980s,-0.15 1990s,0.05 aaron,-0.32 abandoned,-0.09 abby,0.64 ability,-0.03 able,-0.04 abnormal,-0.34 aboard,-0.15 above,0.2 abrupt,-0.83 abruptly,-1.11 abs,0.58 absence,-0.8 absent,0.08 absolute,-1.51 absolutely,0.57 abstract,-0.09 absurd,-1.23 abundant,0.83
(all of this a-z)
ReviewTester.java
public class ReviewTester { public static void main(String[] args) { //Test your fakeReview method here! } }
SimpleReview.txt
This was a terrible restaurant! The pizza crust was too chewy, and I disliked the pasta. I would definitely not come back.
negativeAdjectives.txt
aggressive arrogant belligerent bigoted blunt callous critical cynical dishonest distant envious greedy guarded hostile indifferent intolerant irresponsible jealous pessimistic prejudiced prideful resentful rude sad selfish skeptical suspicious thoughtless unemotional untrusting
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
