Write the scoreList method moveUp that compares the highScore of the Player object at the index pos to each Player in the list above it. This object will be moved to the correct position in the list (you may assume that all items with an index smaller than pos in the list are in the correct order).

Respuesta :

Answer:

private void moveUp(int pos){    for(int i=pos;i<scoreboard.size()-1;i++){ // iterate from pos to end of the array. Player p=scoreboard.get(i);                      //get the ith player Player t=scoreboard.get(i+1);                      //get the (i+1) player i.e immediate next player if(p.highScore < t.highScore){                      //check if current player highScore < next player highScore scoreboard.set(i+1,p);                           //just exchange the elements i.e players scoreboard.set(i,t);    } } }

Explanation:

Utilities used in the code:-

Following are the methods used in the code above:-

get(index) - This method returns the element at a specific index from the list.

set(index,element) - This method updates a element at specific element to new element.

size() - This method returns the size of the array list.