A website uses the Rating class to store information about ratings of publications. It has two integer fields: upVotes and downVotes , and implements the Comparable interface. Your task is to write its compareTo method. Two Rating objects must be compared by a "net rating" which is calculated as a difference between the number of upvotes and the number of downvotes.
Computer scienceProgramming languagesJavaCode organizationObject-oriented programmingClass hierarchiesInterfaces and abstract classes
Comparable
Ratings
Report a typo
Write a program in Java 17
import java.util.*;
class Rating implements Comparable<Rating> {
private int upVotes;
private int downVotes;
public int getUpVotes() {
return upVotes;
}
public void setUpVotes(int upVotes) {
this.upVotes = upVotes;
}
public int getDownVotes() {
return downVotes;
}
public void setDownVotes(int downVotes) {
this.downVotes = downVotes;
}
@Override
public int compareTo(Rating rating) {
// write your code here
return 0;
}
}
// do not change the code below
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
List<Rating> list = new ArrayList<>();
while (sc.hasNextLine()) {
int[] votes = Arrays.stream(sc.nextLine().split(" "))
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.