Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone help me with this java question Your task for this lab is to implement and test a class to store ratings of items.
Can someone help me with this java question
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() - display the average rating and how many 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 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 If your class is used with this driver code: + rl); Rating r1 = new Rating(); System.out.println("r1: rl.addRating (5); System.out.println("r1: rl.addRating (3.5); System.out.println("r1: + rl); + rl); Rating r2 = new Rating (40, 10); System.out.println("r2: " + r2); Rating r3 = new Rating (12.75, 3); System.out.println("r3: " + r3); ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started