Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this task, you will test and implement the following specs: Note: All methods are public and non - static, unless otherwise noted, from this

In this task, you will test and implement the following specs:
Note: All methods are public and non-static, unless otherwise noted, from this point forward in the course.
ratings.Song - In the ratings package, a class named Song
This class will have a constructor that takes 3 parameters in this order:
A String representing the title of the Song
A String representing the artist of the Song
A String representing the Songs ID
Song will have getter and setter methods for the three constructor parameters named:
getTitle
setTitle
getArtist
setArtist
getSongID -- Note that both characters in ID are capital
setSongID
For this task, you don't need to implement any additional methods in the Song class (We will add to this class in
later tasks)
ratings.Rating - In the ratings package, a class named Rating
This class will have a constructor that takes 2 parameters in this order:
A String representing the ID of the reviewer who gave the rating
An int representing the rating that the reviewer gave
Rating will have getter and setter methods for the two constructor parameters named:
getReviewerID
setReviewerID
getRating
setRating
Ratings must be in the range 1-5. If someone calls setRatings with an invalid rating, the rating should be set to -1
to indicate that an error has occurred. (eg. setRating(100) should result in the rating being set to -1). This check
must also apply when the constructor is called with an invalid rating.
ratings.Reviewer - In the ratings package, a class named Reviewer
This class will have a constructor that takes 1 parameter:
A String representing the ID of the reviewer
Reviewer will have getter and setter methods for the constructor parameter named:
getReviewerID
setReviewerID
rateSong - Reviewer will have a method named rateSong that takes an int as a parameter and returns a
reference to a new Rating object (Using the Rating class described above) with this reviewer's ID and the rating
from the parameter of this method.
Note: You can see feedback in Autolab for your testing utilities and tests without completing the programming portion of
this task, but you must at least create the classes and methods that you test. You can "stub out" these methods by having
them always return a fixed value, but they must exist so the grading code, and your tests, can compile and run. Testing Utilities
To help you write your tests, you will write several testing utility methods. These methods are meant to help you write your
unit tests. These methods will compare Song, Rating, and Reviewer objects for equality. When writing test cases, you should
create an object with the values that you expect, call the method to be tested to create an object of the same type, then call
your utility method to check if the 2 objects contain all the same values.
Create a class named TestClasses 1 in the tests package (tests.TestClasses1) and write the following methods in that class
(Note: Do not add the @Test annotation to these methods since they are not tests):
compareSongs - Write a method named compareSongs in the tests. TestClasses 1 class that:
Takes [references to]2 Song objects as parameters
Returns a boolean that is true if the title, artist, and id of both Songs are exactly the same. The method either
returns false, or fails a JUnit assert, if the Songs do not have all the same values
If the 2 Songs do not have all the same values you can either: return false, or have an assert that fails. This gives
you the option of using assertTrue, assertEquals, etc. in your utility methods instead of returning false when the
test should fail. It is recommended that you write this method with assert statements, then add "return true" as
the last line of the method. The method will never return false, but if any assert fails the test will fail without
reaching your "return true" line. If you chose to not use asserts and instead return false when the Songs are not
identical, be sure to add assertTrue in your test cases when you call this method. (This structure is the same for all
utility methods)
compareRatings - Write a method named compareRatings in the tests.TestClasses1 class that
Takes [references to]2 Rating objects
Returns a boolean that is true if the rating and reviewerID of both Ratings are exactly the same. The method
either returns false, or fails a JUnit assert, if the Ratings do not have all the same values
compareReviewers - Write a method named compareReviewers in the tests.TestClasses1 class that
Takes [references to]2 Reviewer objects
Returns a boolean that is true if the reviewerID of both Reviewers are exactly the same. The method either
returns false, or fails a JUnit assert, if the Reviewers do not have the same reviewerID
Testing Requirements
Add test methods to the tests.TestClasses1 class, using the @Test annotation, that tests all the methods in the Specification
section. You should call your testing utility methods to save time while writing these tests.
Programming Requirements
Implement the Song,
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions