Menu

Wanted Advice Code M Getting Compiling Errors Q43870521

Just wanted some advice on my code, I’m gettingcompiling errors.Java 7 Autocomplete Ready O 1 > import java.io.*;. 10 class Result { * Complete the bestPros function below. * The function

Java 7 Autocomplete Ready O 1 > import java.io.*;. 10 class Result { * Complete the ‘bestPros’ function below. * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. 2D_INTEGER_ARRAY pros * 2. INTEGER K * public static List<Integer> bestPros(List<List<Integer>> pros, int k) { // Write your code here Integer[][] bestpros; When a Thumbtack user creates a new project, we recommend the best Pros for the job based on a metric called the Pro Matching Score (PMS). This score is calculated using two factors: the distance the Pro would have to travel to the job, and the Pro’s average rating. More specifically, PMS is defined as (max_distance – distance) * rating, where max_distanceis the maximal distance that any Pro has from the given user. Naturally, a higher PMS means the Pro is a better match for the project. You have an array that represents the Pros who are available to complete a new project for a user, where each element of the array is a distance, rating) tuple. distance is the distance of the Pro from the user’s project location, and rating is their overall rating. Given the array pros for a specific project, determine the kPros who are best suited to complete it, based on their Pro Matching Score. Return a list of the indices (0-based) at which these Pros appeared in the original pros array, sorted by their PMS score. In the case of a PMS tie, the Pro with the smaller index goes first. Example For pros = [[5, 4], [4, 3], [6, 5], [3, 5]] and k = 2, the output should be bestPros(pros, k) = [3, 1]. The PMSs of the Pros are: Integer[] bestKpros; //Find max value in pros array int max = Integer.MIN_VALUE; for (int i = 0; i < pros.size(); i++) { for(int j = 0; j <pros.get(i).size(); j++){ if (pros.get(i).get(j) > max) { max = pros.get(i).get(i); for (int i = 0; i < pros.size(); i++) { int pro = (max – pros.get(i).get() * pros.get(i).get(1)); ArrayList<Integer> temp = new ArrayList<Integer>(); temp.add(pro); temp.add(i); bestpros.add(temp); . oth pro: (6 – 5) * 4 = 4; Arrays.sort (bestpros, Collections. reverseOrder()); • 1st pro: (6 – 4) + 3 = 6; • 2nd pro: (6 – 6) * 5 = 0; for(int i = 0; i < bestpros. length && i <k; i++) { bestKpros.add(bestproslili. • 3rd pro: (6 – 3) * 5 = 15. Arrays.sort (bestKpros); The output is [3, 1] since the Pros at indices 1 and 3 have the highest scores. Since pro [3] has a higher PMS than pro[1], index 3 appears first in the array return bestKpros; } Show transcribed image text Java 7 Autocomplete Ready O 1 > import java.io.*;. 10 class Result { * Complete the ‘bestPros’ function below. * The function is expected to return an INTEGER_ARRAY. * The function accepts following parameters: * 1. 2D_INTEGER_ARRAY pros * 2. INTEGER K * public static List bestPros(List pros, int k) { // Write your code here Integer[][] bestpros; When a Thumbtack user creates a new project, we recommend the best Pros for the job based on a metric called the Pro Matching Score (PMS). This score is calculated using two factors: the distance the Pro would have to travel to the job, and the Pro’s average rating. More specifically, PMS is defined as (max_distance – distance) * rating, where max_distanceis the maximal distance that any Pro has from the given user. Naturally, a higher PMS means the Pro is a better match for the project. You have an array that represents the Pros who are available to complete a new project for a user, where each element of the array is a distance, rating) tuple. distance is the distance of the Pro from the user’s project location, and rating is their overall rating. Given the array pros for a specific project, determine the kPros who are best suited to complete it, based on their Pro Matching Score. Return a list of the indices (0-based) at which these Pros appeared in the original pros array, sorted by their PMS score. In the case of a PMS tie, the Pro with the smaller index goes first. Example For pros = [[5, 4], [4, 3], [6, 5], [3, 5]] and k = 2, the output should be bestPros(pros, k) = [3, 1]. The PMSs of the Pros are: Integer[] bestKpros; //Find max value in pros array int max = Integer.MIN_VALUE; for (int i = 0; i

Expert Answer


Answer to Just wanted some advice on my code, I’m getting compiling errors….

OR