Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (25 points) Fill in the template below to make a complete class definition for a class that describes a very simplified scoreboard for a

image text in transcribed
image text in transcribed
image text in transcribed
2. (25 points) Fill in the template below to make a complete class definition for a class that describes a very simplified scoreboard for a video game. The scoreboard is implemented using two ArrayLists - one list to store the name of the player, and a second one to store the player's score. The two lists are stored in parallel - meaning that the indices of a player and their score will be the same. For example, the player at index 0 in the list players will have their score stored at index in the list scores The class's constructor and mutator methods MUST be implemented with the following constraints: 1. The sizes of the two lists must be the same at the end of any SimpleScoreboard method call. 2. The strings in the list players must always be unique 3. A player at position n in the list players will have their score at position n in the list scores Make sure your code conforms to the instructions given in the comments for each method. Note: You are also being asked to write the code for a private helper method named getIndexOfPlayer Make sure you are using this method in your accessors and mutators where appropriate to receive full credit! You may use the ArrayList methods on the back page when solving this problem. public class SimpleScoreboard { private ArrayList players; /List of players private ArrayList scores;// List of scores public // Constructor that takes no parameters. The initial lists // of players and scores must be empty. private int getIndexOfPlayer (String playerName) { // Helper method that takes a string as a parameter and if the String // is in the list players returns its index in the list. Otherwise // returns a -1. public add( // Mutator method that takes a player and their score as // parameters. Returns false if the player is already in the list, // otherwise adds the player and their score to the end of the // appropriate lists and returns true. public lookup // Accessor method that takes a String as a parameter and if it is // in the players list returns their score. If it is not in the // players list returns a -1. public getListof players // Accessor method that takes no parameters and returns the list // of players. public update // Mutator method that takes a player and their score as // parameters. Returns false if the player is not already in the // list, otherwise replaces the score of the player with the new // score and returns true. public remove ) 1 / Mutator method that takes a player name as a parameter. Returns false if the player is not already in the list, otherwise removes // both the player and their score from the two lists and returns // true. Page 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

T Sql Fundamentals

Authors: Itzik Ben Gan

4th Edition

0138102104, 978-0138102104

More Books

Students also viewed these Databases questions

Question

5. Structure your speech to make it easy to listen to

Answered: 1 week ago

Question

1. Describe the goals of informative speaking

Answered: 1 week ago