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

Use either Java to implement a program to solve the following problem. Write a c

ID: 3547879 • Letter: U

Question

Use either Java to implement a program to solve the following problem. Write a class that keeps track of high scores for a game. As games are completed the score is added to the "Scores" class with an add method. When desired, the names and scores of the top players can be output. Don't worry about duplication (e.g. the same player might have the top 3 scores).


Implement a solution for this problem using the Bridge pattern.


Abstraction: A "Scores" class or interface that keeps track of the high scores. It should have methods for the following operations:


1. void addScore(string name, int score) // Adds the specified score and name to the system
2. string [] getHighNames() // Returns an array of the names of the top scorers, sorted from highest to lowest

3. int [] getHighScores() // Returns an array of the top scores, sorted from highest to lowest
You can either make an Abstract class/interface along with a concrete abstraction, or just a single concrete class for the abstraction if you wish. This class creates an instance of the Implementor to do most of the work.


Implementor: An abstract class or interface named "ScoresImpl"
1. void addScore(string name, int score)
2. int getNumEntries()
2. string getHighName(int index) // Returns the name of the player at the specified index
3. int getHighScore(int index) // Returns the score of the player at the specified index


Concrete Implementation 1: A concrete class named "ScoresTopThree". This class implements "ScoresImpl" but is fixed to always have exactly the three top scores. Any scores that are added not in the top three are ignored. Initially, all scores are -1 with a name of "Anonymous". Return a blank string for the name and -1 for the score if the index is out of bounds.


Concrete Implementation 2: A concrete class named "ScoresAll". This class implements "ScoresImpl" but stores every score that is added. Use any data structure you like to store the information (e.g. sorted arrays, ArrayList, List, etc.)


Client: This is your main method. It should create the Abstraction/Scores class, add several scores as a test, then output the high scores. You can manually test to see if the output scores are correct. Test your main method where the Abstraction uses Concrete Implementation 1 and again where it uses Concrete Implementation 2. You should only have to change a single line of code when switching between one and the other. This is the main benefit of using the Bridge class, it makes it easy to swap in/out different implementations of an interface.

Explanation / Answer

//Scores.java

public

Scores {

void addScore(String name, int score);

String[] getHighNames();

int[] getHighScores();

PlayerScore[] getTopPlayers();

}// End of Scores.java

*********************************************************************

//ScoresImpl.java

public

ScoresImpl extends Scores {

void addScore(String name, int score);

int getNumEntries();

String getHighName(int index);

int getHighScore(int index);

}// End of ScoresImpl.java

//PlayerScore.java (Helper classs)

public

}

}

}

}

}

}

}

// End of PlayerScore.java

*********************************************************************

//ScoresAll.java

import

import

public

String[] highScores =

highScores[count++] = p.getPlayerName();

}

}

highScores[count++] = p.getScore();

}

}

}

}

}

}

}

}

PlayerScore[] p =

p[count++] = ps;

}

}

}

// End of ScoresAll.java

//ScoresTopThree.java

import

import

import

public

}

}

String[] highScores =

highScores[count++] = p.getPlayerName();

}

}

highScores[count++] = p.getScore();

}

}

Collections.sort(

}

}

}

}

}

}

PlayerScore[] p =

p[i] =

}

}

}

//End of ScoresTopThree.java

*********************************************************************

//ScoreClient.java (Main class to test all the above classes)

public

Scores scores =

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

scores.addScore(

printScoresAndNames(scores);

}

PlayerScore[] pscores = scores.getTopPlayers();

System.

}

}

System.

}

}

String[] highScores = scores.getHighNames();

System.

}

}

}// End of ScoreClient.java

*********************************************************************

*********************************************************************

In the interest of time, submitted code with a few comments missing...

The entire code is exactly as per the question given

Please Let me know if you need assistance in understanding the code or executing it..

Thank you..

*********************************************************************

*********************************************************************