/** * CS139 - Programming Fundamentals * Department of Computer Science * James Madison University * @version Spring 2016 */
In the previous assignment we developed an application that could automatically determine the sentiment conveyed by some text.
The goal of this assignment is to re-write that application in an
object-oriented style. In particular, the utility
class SentimentUtils
will be replaced
by SentimentAnalyzer
. The SentimentAnalyzer
class will encapsulate a collection of pre-scored reviews along with
the code necessary to analyze novel text using the stored review data.
UPDATED 4/7 You should download
this updated copy of Review.java
for use in this project. (It's the same as the previous version
except that it provides toString
and equals
methods which may be helpful for testing.)
You will be able to reuse the ReviewLoader.java file provided for the previous assignment.
You'll need to create the following files:
The SentimentAnalyzer
class will store a collection of review
objects in an ArrayList
. It will use these stored reviews to
determine the sentiment of some provided text. The completed class must
conform to the following UML diagram:
The value of DEFAULT_SCORE
must be 2.0.
(Note that DEFAULT_SCORE
is underlined in the UML diagram
above. This indicates that it should be a static field.) This value should be used as the default return value for both evaluateWord
and evaluateText
.
Each of the three constructors provide a different mechanism for providing an initial (possibly empty) collection of reviews:
SentimentAnalyzer
object with an empty ArrayList
of
reviews. (It will be possible to add reviews later using
the addReview
method described below).
Review
objects. This constructor will need to transfer the reviews from the
provided array into the ArrayList
.ReviewLoader
class from the previous
assignment.)
The addReview
method must add the provided review to the collection
of reviews stored by the SentimentAnalyzer
object.
The getReviews
method must return a shallow copy
of the ArrayList
of reviews. This means that the ArrayList
should be
copied, but the Review
objects stored in the ArrayList
will not be
copied. The result will be two different ArrayList
s that share
references to the same set of Review
objects.
The evaluateWord
and evaluateText
methods must provide exactly the same functionality as they did in the previous assignment.
The toString
method must return a string with the
following format: "SentimentAnalyzer containing 145 reviews"
(where 145 is replaced with the actual number of reviews stored).
The containsWord
method should be implemented as
a private helper method. (This method only exists to support
the operation of evaluateWord
, so it isn't necessary to
make it accessible outside of this class.)
You must provide JUnit tests for each of the methods in SentimentAnalyzer.java. You should be able to re-purpose many of the tests from the previous assignment with some slight modifications.
You will need to re-write Sentiment.java to use SentimentAnalyzer.java instead of SentimentUtils.java. The functionality should remain exactly the same.
Zip SentimentAnalyzer.java and SentimentAnalyzerTest.java along with any additional text files that you require for testing. Submit the .zip file through Web-CAT. You should not include Sentiment.java or any of the Java files that we have provided.
SentimentAnalyzer.java must conform to the CS 139 Style Guide. You are not required to provide Javadoc comments for the methods in SentimentAnalyzerTest.java, but that file should conform to the style guide in all other respects.
Zip SentimentAnalyzer.java and Sentiment.java and submit through Web-CAT. Your zip file should only contain these two java files. You should not include the Java files that we provided or any testing code. Both SentimentAnalyzer.java and Sentiment.java must conform to the CS 139 Style Guide.
Your submission will be graded using the following criteria:
Points | |
---|---|
Part A Web-CAT Correctness/Testing | 40 |
Part A Checkstyle Tests | 10 |
Part B Web-CAT Correctness/Testing | 10 |
Part B Checkstyle Tests | 10 |
Style and Code Organization | 30 |
If Web-CAT deducts any points for correctness/testing, for parts A or B you will receive at most 50% of the points for that part.
Once again there will be a penalty for excessive submissions. The first 10 submissions for each part are free. Each submission beyond 10 will result in a .5 reduction in the final score.
This assignment must be completed individually. Your submission must conform to the JMU Honor Code. Authorized help is limited to general discussion on Piazza, the lab assistants assigned to CS 139, and the instructor. Copying work from another student or the Internet is an honor code violation and will be grounds for a reduced or failing grade in the course.