Purpose To review interfaces Directions Your task for this lab is to implement and test a class to store ratings of items. Your Rating class should have the following fields and methods: private double sumofRatings - the sum of all of the ratings private int raters - the number of people who have rated an item public Rating () - initialize both fields to zero public Rating (double sumofRatings, int raters) - initialize the fields to the parameter values public void addRating (double newRating) - increase the sumofRatings by newRating and increase the number of raters by one public double getAverageRating () - return the average rating; if there are no raters so far, return 0.0 public String tostring () reviews it is based on; for example, if the sum of the ratings is 32 and that is based on ratings from ten people, the toString method will display the average rating and how many return "3.2 based on 10 reviews" Your Rating class should also implement the Comparable interface - Ratings should be sorted such that the highest average rating appears first. If two Rating objects have the same average, the one with the higher number of reviews should appear first.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
5 Stars (1).pdf
PDF
O File | C:/Users/19377/Downloads/5%20Stars%20(1).pdf
+
Example
If your class is used with this driver code:
Rating r1 = new Rating();
System.out.println("rl:
rl.addRating (5);
System.out.println("rl: "
rl.addRating (3.5);
System.out.println("rl: " + r1);
+ rl);
+ rl);
Rating r2 =
new Rating (40, 10);
System.out.println("r2: " + r2);
Rating r3
System.out.println("r3:
= new Rating(12.75, 3);
+ r3);
ArrayList<Rating> ratings
ratings.add (r1);
ratings.add (r2);
ratings.add (r3);
Collections.sort(ratings);
new ArrayList<>();
%3D
for (Rating r: ratings) {
System.out.println (r);
}
it should produce this output:
rl: 0.0 based on 0 reviews
rl: 5.0 based on 1 reviews
rl: 4.25 based on 2 reviews
r2: 4.0 based on 10 reviews
r3: 4.25 based on 3 reviews
4.25 based on 3 reviews
4.25 based on 2 reviews
4.0 based on 10 reviews
9:49 PM
e Type here to search
26°F Cloudy
1/17/2022
(8)
Transcribed Image Text:5 Stars (1).pdf PDF O File | C:/Users/19377/Downloads/5%20Stars%20(1).pdf + Example If your class is used with this driver code: Rating r1 = new Rating(); System.out.println("rl: rl.addRating (5); System.out.println("rl: " rl.addRating (3.5); System.out.println("rl: " + r1); + rl); + rl); Rating r2 = new Rating (40, 10); System.out.println("r2: " + r2); Rating r3 System.out.println("r3: = new Rating(12.75, 3); + r3); ArrayList<Rating> ratings ratings.add (r1); ratings.add (r2); ratings.add (r3); Collections.sort(ratings); new ArrayList<>(); %3D for (Rating r: ratings) { System.out.println (r); } it should produce this output: rl: 0.0 based on 0 reviews rl: 5.0 based on 1 reviews rl: 4.25 based on 2 reviews r2: 4.0 based on 10 reviews r3: 4.25 based on 3 reviews 4.25 based on 3 reviews 4.25 based on 2 reviews 4.0 based on 10 reviews 9:49 PM e Type here to search 26°F Cloudy 1/17/2022 (8)
5 Stars (1).pdf
PDF
O File | C:/Users/19377/Downloads/5%20Stars%20(1).pdf
+
U DL uI D
Purpose
To review interfaces
Directions
Your task for this lab is to implement and test a class to store ratings of items. Your
Rating class should have the following fields and methods:
private double sumofRatings
the sum of all of the ratings
private int raters
the number of people who have rated an item
public Rating ()
initialize both fields to zero
public Rating(double sumOfRatings, int raters)
to the parameter values
initialize the fields
increase the sumOfRatings by
public void addRating (double newRating)
newRating and increase the number of raters by one
public double getAverageRating ()
are no raters so far, return 0.0
return the average rating; if there
public String toString ()
reviews it is based on;
display the average rating and how many
for example, if the sum of the ratings is 32
and that is based on ratings from ten people, the toString method will
return "3.2 based on 10 reviews"
Your Rating class should also implement the Comparable interface – Ratings
should be sorted such that the highest average rating appears first. If two Rating
objects have the same average, the one with the higher number of reviews should
appear first.
Example
If your class is used with this driver code:
Rating r1
System.out.println("rl: "
rl.addRating (5);
System.out.println("r1:
rl.addRating (3.5);
= new Rating();
+ r1);
+ r1);
System out
nrintln ("r1:
r1).
9:49 PM
e Type here to search
26°F Cloudy
1/17/2022
(8)
Transcribed Image Text:5 Stars (1).pdf PDF O File | C:/Users/19377/Downloads/5%20Stars%20(1).pdf + U DL uI D Purpose To review interfaces Directions Your task for this lab is to implement and test a class to store ratings of items. Your Rating class should have the following fields and methods: private double sumofRatings the sum of all of the ratings private int raters the number of people who have rated an item public Rating () initialize both fields to zero public Rating(double sumOfRatings, int raters) to the parameter values initialize the fields increase the sumOfRatings by public void addRating (double newRating) newRating and increase the number of raters by one public double getAverageRating () are no raters so far, return 0.0 return the average rating; if there public String toString () reviews it is based on; display the average rating and how many for example, if the sum of the ratings is 32 and that is based on ratings from ten people, the toString method will return "3.2 based on 10 reviews" Your Rating class should also implement the Comparable interface – Ratings should be sorted such that the highest average rating appears first. If two Rating objects have the same average, the one with the higher number of reviews should appear first. Example If your class is used with this driver code: Rating r1 System.out.println("rl: " rl.addRating (5); System.out.println("r1: rl.addRating (3.5); = new Rating(); + r1); + r1); System out nrintln ("r1: r1). 9:49 PM e Type here to search 26°F Cloudy 1/17/2022 (8)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY