Create a class named BaseballGame that contains data fields for two team names and scores for each
Question:
Create a class named BaseballGame that contains data fields for two team names and scores for each team in each of nine innings. Create get and set methods for each field; the get and set methods for the scores should require a parameter that indicates which inning’s score is being assigned or retrieved. Do not allow an inning score to be set if all the previous innings have not already been set. If a user attempts to set an inning that is not yet available, issue an error message. Also include a method that determines the winner of the game after scores for the last inning have been entered.
(For this exercise, assume that a game might end in a tie.) Create two subclasses from BaseballGame: HighSchoolBaseballGame and LittleLeagueBaseballGame. High school baseball games have seven innings, and Little League games have six innings. Ensure that scores for later innings cannot be accessed for objects of these subtypes. Write three applications that each instantiate one of the object types and demonstrate their methods.
Save the files as BaseballGame.java, HighSchoolBaseballGame.java, LittleLeagueBaseballGame.java, DemoBaseballGame.java, DemoHSBaseballGame.java, and DemoLLBaseballGame.java.
Step by Step Answer: