Please help me to solve the error in the following java code. The question requirement is to merge k arrays into a single sorted array, the output should be: (Winnie, 0), (Eason Chan, 40), (Gloria...


Please help me to solve the error in the following java code.


The question requirement is to merge k arrays into a single sorted array, the output should be:


(Winnie, 0), (Eason Chan, 40), (Gloria Tang, 60), (Andy Lau, 60), (McDull, 60), (Denise Ho, 60), (Jennifer Chan, 70), (Joey Yung, 80), (Kay Tse, 90), (Mickey, 90), (Jacky Cheung, 95), (Teddy, 95), (Anita Mui, 100), (Peppa, 100)


import java.util.*;
import java.util.Arrays;



public class StableMerger {

    static class Student {
        String name;
        double grade;


        public Student(String n, double g) {
            name = n;
            grade = g;
        }


        public String toString() {
            return "(" + name + ", " + grade + ")";
        }




    }



    public static Student[] merge(Student[][] a) {

    //↓↓↓↓↓↓error code↓↓↓↓↓↓

     PriorityQueue queue = new PriorityQueue();
     int total=0;


        //add arrays to heap
        for (int i = 0; i < a.length;="" i++)="">
            queue.add(new Student[] a(0));
            total = total + a[i].length;
        }


        int m=0;
        int result[] = new int[total];


        //while heap is not empty
        while(!queue.isEmpty()){
            Student ac = queue.poll();
            result[m++]=ac.a[ac.grade];


            if(ac.grade <>
                queue.add(new Student(ac.a, ac.grade+1));
            }
        }


        return result;


//⇈⇈⇈error code⇈⇈⇈
    }



    public static void main(String[] args) {
        String[][] names = {{"Gloria Tang", "Andy Lau", "McDull"},
                {"Eason Chan", "Denise Ho", "Jennifer Chan", "Joey Yung", "Kay Tse", "Jacky Cheung", "Anita Mui"},
                {"Winnie", "Mickey", "Teddy", "Peppa"}};
        double[][] grades = {{60, 60, 60}, {40, 60, 70, 80, 90, 95, 100}, {0, 90, 95, 100}};
        Student[][] a = new Student[names.length][];
        for (int i = 0; i < names.length;="" i++)="">
            a[i] = new Student[names[i].length];
            for (int j = 0; j < names[i].length;="">
                a[i][j]= new Student(names[i][j], grades[i][j]);
        }
        System.out.println(Arrays.toString(merge(a)));
    }
}

Jun 11, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here