Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Let\'s say item 1 is our Quiz Average, item 2 is Midterm1, item 3 is Midterm2, a

ID: 3849403 • Letter: L

Question

Let's say item 1 is our Quiz Average, item 2 is Midterm1, item 3 is Midterm2, and item 4 is the Final, and suppose the rank array is:

[2, 4, 1, 3]

Since rank[1] = 2, that means you did the best on item 2, which is Midterm1, which will optimally count for 30%.
Since rank[2] = 4, that means you did the next best on item 4, which is the Final, which will optimally count for 45%.
Since rank[3] = 1, that means you did the next best on item 1, which is the Quiz Average, which will optimally count for 5%.
Since rank[4] = 3, that means you did the next best on item 3, which is the Midterm2, which will optimally count for 20%.

Therefore, the array "optimal" that should be returned is the following:

[ 5, 30, 20, 45]

optimal[1] =   5 because we want item 1, which is the Quiz Average, to count for 5%.
optimal[2] = 30 because we want item 2, which is Midterm1, to count for 30%.
optimal[3] = 20 because we want item 3, which is Midterm2, to count for 20%.
optimal[4] = 45 because we want item 4, which is the Final, to count for 45%.

In other words, optimal[i] should be the percentage of item i.

public class HW2_Define {

public static int [] findBest(int n, int [] lowest, int [] highest, int [] rank) {

int [] optimal = new int[n+1];
  
// DEFINE THIS METHOD HERE...
  


// RETURN optimal here...
return optimal;
}

Explanation / Answer

What I got from the description is we have to print the optimal value for a rank specified. So, that is not hard to code provided you have been given the rank array. I don't know what other paramters the program has taken. It would have been better if you could post the complete program. Anyways, the logic behind is just simple. Iterate over the array and check what value it is and use if-else to assign the values . As this is java programming so your method should be something like this.

for(int i=0;i<rank.length;i++){
if(rank[i]== 1) optimal[i] = 5;
else if(rank[i] == 2 ) optimal[i] = 30;
else if(rank[i]== 3) optimal[i] = 20;
else if (rank[i]== 4) optimal[i] = 45;
}

Just put the above code in the method and you will be good to go. Let me know if you have any further doubts.