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.
PriorityQueue
Comparing by score summary
Report a typo
Sample Input 1:
95 95
90 90
95 100Sample Output 1:
95 100
95 95
90 90Write 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;
}
___
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.