Comparing by score summary

Report a typo

Implement the compare() method to store PriorityQueue elements ordering by the sum of its two fields and print them. There are 3 elements in the queue. The highest score sum should be in the head. The printing format should be mathScore + " " + physicalScore.

Sample Input 1:

95 95
90 90
95 100

Sample Output 1:

95 100
95 95
90 90
Write a program in Java 17
import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Queue<Person> queue = createQueue(scanner);

// Print here
}

public static Queue<Person> createQueue(Scanner scanner) {
Queue<Person> queue = new PriorityQueue(new PersonComparator());
queue.add(new Person(scanner.nextInt(), scanner.nextInt()));
queue.add(new Person(scanner.nextInt(), scanner.nextInt()));
queue.add(new Person(scanner.nextInt(), scanner.nextInt()));

return queue;
}
}

class Person {
private int mathScore;
private int physicsScore;

public Person(int mathScore) {
this.mathScore = mathScore;
}

public Person(int mathScore, int physicsScore) {
this.mathScore = mathScore;
this.physicsScore = physicsScore;
}

public int getMathScore() {
return mathScore;
}
___

Create a free account to access the full topic