icon

UseTopicwritingscode to get 5% OFF on your first order!

Java Code

Code must be written to satisfy this.

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.
    * Include a private property called gamePlayed to contain the name of the game being played.
    * 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.
    * Include a new public method, addName(), to accept a players 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.)
    * Include a public method, getPlayerName(), to accept the number of the player and return the players name.
    * Include a public method setGame() to update the gamePlayed property by passing it a string containing the name of the game.
    * Include a public method getGame() to retrieve the name of the game.
    * Include a public method, addScore(), to update a players score by passing it the players name and the points to be added. Return the updated score.
    * Include a public method, subScore(), to update a players score by passing it the players name and the points to be subtracted. Return the updated score.
    * Include a new public method, listAllScores(), to print the name of the game being played, the names of each player and their respective scores.
    * 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.
    * Add private integer properties for fouls, balls, strikes, and outs.
    * 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
    * 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.
    * Include a public method, getOuts(), to return the current number of outs.
    * Include a public method, advStrikes(), to add 1 to the number of strikes. If the number of strikes reaches 3, call advOuts().
    * Include a public method, getStrikes(), to return the current number of strikes.
    * 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.
    * Include a public method, getFouls(), to return the current number of fouls.
    * 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.
    * Include a public method, getBalls(), to return the current number of balls.
    * Include a public method, getInning(), to return the current inning.
    * 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 Assessments output, we will use the following method:
    * Print to the console the message, Assessment 10 Classes and Inheritance followed by a blank line.
    * Print Section 3: Base Class Results After Adding to the console followed by a blank line.
    * Instantiate an object called gameOne, from the scoreKeeper class, passing Canasta as the game name to the constructor.
    * Call the addName() method three times to add the players, Larry, Moe, and Curly.
    * Print a blank line to the console for ease of reading.
    * Call the objects addScore() method three times. Once for Larry adding 20 points to his score. A second time for Moe adding 35 points to Curlys score. Then a third time for Curly, adding 45 points to Curlys score.
    * Using the listAllScores() method, print a report of the players and their respective scores to the console.
    * Call the objects subScore() method twice. Once for Moe subtracting 15 points from his score. The second time, subtract 5 points from Curlys score.
    * Print Section 3: Base Class Results After Subtracting to the console followed by a blank line
    * Using the listAllScores() method, print a report of the players and their respective scores to the console.
    * 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 Assessments output, we will use the following method:
    * Print Section 4: Derived Class Results: Baseball scoring to the console followed by a blank line.
    * 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.
    * The following method calls should be done in order to guarantee the correct results.
        * Call the addScore() method to advance the Cubs score by 2.
        * Call the advOuts() method three times.
        * Call the addScore() method to advance the Braves score by 3.
        * Call the advOuts() method once.
        * Call the advStrikes() method once.
        * Call the advFouls() method thrice.
        * Call the advBalls() method once.
        * Call the listAllScores() method to print the game and scores. Also, print a blank line to the console.
        * 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

You can leave a response, or trackback from your own site.

Leave a Reply

Powered by WordPress | Designed by: Premium WordPress Themes | Thanks to Themes Gallery, Bromoney and Wordpress Themes