Instructions In this scenario, your group has been tasked with creating a score keeping program for games. You have been assigned to create and test the classes necessary. You will create a single,...

1 answer below »
Hello, I am looking for help with my Java assignment. Attached is the assignment.


Instructions In this scenario, your group has been tasked with creating a score keeping program for games. You have been assigned to create and test the classes necessary. You will create a single, console program with multiple sections. In it, you will create a base class and an inherited class. Then you will write code to instantiate objects from each class and test their functionality. The program for this Assessment will consist of four sections, each headed by the three-line comment below: //********************************************************* //****Assessment 5 Section X //********************************************************* (where X stands for the portion of the Assessment to follow.) Section 1: 1. Enter the comment with the section title as described above. 2. Create a base class called scoreKeeper. a. Include a private property called gamePlayed to contain the name of the game being played. b. Add a private property which will allow for any number of players. A dictionary or dynamic array would be a good option. The container will hold the names and scores of the players. c. Include a new public method, addName(), to accept a player’s name and insert it into the container. (Note: If the container you used does not have an add method to easily add a value, you will need to include code to determine the next available position.) d. Include a public method, getPlayerName(), to accept the number of the player and return the player’s name. e. Include a public method setGame() to update the gamePlayed property by passing it a string containing the name of the game. f. Include a public method getGame() to retrieve the name of the game. g. Include a public method, addScore(), to update a player’s score by passing it the player’s name and the points to be added. Return the updated score. h. Include a public method, subScore(), to update a player’s score by passing it the player’s name and the points to be subtracted. Return the updated score. i. Include a new public method, listAllScores(), to print the name of the game being played, the names of each player and their respective scores. j. Include two constructors. The first one is a default constructor. The second is a constructor method which will accept the name of the game and call the setGame(). Section 2: 1. Enter the comment with the section title as described above. 2. Some games have additional information that must be monitored during play. Create a sub-class called baseball that inherits from the base class scoreKeeper. a. Add private integer properties for fouls, balls, strikes, and outs. b. Add a private decimal property to hold the inning number. Whole numbers will indicate the top of the inning and half numbers will indicate the bottom. e.g. 5.5 would indicate the bottom of the 5th c. Include a public method, advOuts(), to add 1 to the number of outs. If the number of outs reaches 3, reset balls, strikes, fouls and outs to 0 and add .5 to innings. d. Include a public method, getOuts(), to return the current number of outs. e. Include a public method, advStrikes(), to add 1 to the number of strikes. If the number of strikes reaches 3, call advOuts(). f. Include a public method, getStrikes(), to return the current number of strikes. g. Include a public method, advFouls(), to add one to the number of fouls. If the number of strikes is less than 2, advFouls() should also add one to strikes. h. Include a public method, getFouls(), to return the current number of fouls. i. Include a public method, advBalls(), to add one to the number of balls. If the number of balls reaches 4, reset balls, strikes and fouls. (This means the player has been given a walk to first base but does not guarantee and runs were scored. j. Include a public method, getBalls(), to return the current number of balls. k. Include a public method, getInning(), to return the current inning. l. Include two constructors. The first one is a default constructor. The second is a constructor method which will accept the name of the home team followed by the name of the visiting team. It will then call the setGame() and pass it a combined name such as “Cubs vs Braves”. It will also call the addName() method to add the two teams to the players property. Section 3: 1. Enter the comment with the section title as described above. 2. Write code to test the base class. This can be done multiple ways and should be when throughly testing your code. However, for this Assessment’s output, we will use the following method: a. Print to the console the message, “Assessment 10 – Classes and Inheritance” followed by a blank line. b. Print “Section 3: Base Class Results After Adding” to the console followed by a blank line. c. Instantiate an object called gameOne, from the scoreKeeper class, passing “Canasta” as the game name to the constructor. d. Call the addName() method three times to add the players, “Larry”, “Moe”, and “Curly”. e. Print a blank line to the console for ease of reading. f. Call the object’s addScore() method three times. Once for Larry adding 20 points to his score. A second time for Moe adding 35 points to Curly’s score. Then a third time for Curly, adding 45 points to Curly’s score. g. Using the listAllScores() method, print a report of the players and their respective scores to the console. h. Call the object’s subScore() method twice. Once for Moe subtracting 15 points from his score. The second time, subtract 5 points from Curly’s score. i. Print “Section 3: Base Class Results After Subtracting” to the console followed by a blank line j. Using the listAllScores() method, print a report of the players and their respective scores to the console. k. Print two blank lines to the console. Section 4: 1. Enter the comment with the section title as described above. 2. Write code to test the sub-class. This can be done multiple ways and should be when thoroughly testing your code. However, for this Assessment’s output, we will use the following method: a. Print “Section 4: Derived Class Results: Baseball scoring” to the console followed by a blank line. b. Instantiate an object called gameTwo, from the baseball class, passing “Cubs” and “Braves” as the teams, (or teams of your choosing), to the constructor. (Note: If you choose to use different team names, be sure you substitute them below for ‘Cubs’ or ‘Braves’. c. The following method calls should be done in order to guarantee the correct results. i. Call the addScore() method to advance the Cubs’ score by 2. ii. Call the advOuts() method three times. iii. Call the addScore() method to advance the Braves’ score by 3. iv. Call the advOuts() method once. v. Call the advStrikes() method once. vi. Call the advFouls() method thrice. vii. Call the advBalls() method once. viii. Call the listAllScores() method to print the game and scores. Also, print a blank line to the console. ix. Use the appropriate get methods to print the current inning, outs, strikes, fouls, and balls. EXPECTED OUTPUT Assessment 10 - Classes and Inheritance Section 3: Base Class Results After Adding The scores for Canasta: Larry's score is 20 Moe's score is 35 Curly's score is 45   Section 3: Base Class Results After Subtracting The scores for Canasta: Larry's score is 20 Moe's score is 20 Curly's score is 40   Section 4: Derived Class Results: Baseball scoring The scores for Cubs vs Braves: Cubs's score is 2 Braves's score is 3   The current inning is 1.5 Outs: 1 Strikes: 2 Fouls: 3 Balls: 1
Answered Same DayFeb 28, 2021

Answer To: Instructions In this scenario, your group has been tasked with creating a score keeping program for...

Rohith answered on Mar 11 2021
146 Votes
//*********************************************************
//****Assessment 5 Section 1
//*********************************************************

import java.util.*;
class scoreKeeper {
scoreKeeper(String name) {
setGame(name);
}
scoreKeeper() {
};
private String gamePlayed;
Dictionary dict = new Hashtable();
public void addName(String name, int number) {
dict.put(name, number);
}
// public String getPlayerName(int number) {
// Integer pName = dict.get(number);
// dict.
// }
public void setGame(String game) {
gamePlayed = game;
}
public String getGame() {
return gamePlayed;
}
public void addScore(String name, int score) {
int currentScore = dict.get(name);
int updatedScore = currentScore + score;
((Hashtable) dict).replace(name, updatedScore);
}
public void subScore(String name, int score) {
int currentScore = dict.get(name);
int updatedScore = currentScore - score;
((Hashtable) dict).replace(name, updatedScore);
}
public void listAllScores() {
System.out.println("The Scores for " + gamePlayed + ": \n");
Enumeration keys = dict.keys();
while (keys.hasMoreElements()) {
String temp = keys.nextElement();
System.out.print(temp + "'s score is: ");
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here