A baseball1 game is played by two teams, generically referred to as home and visitor.2 A game consists of a sequence of innings, numbered starting at one, each of which has two halves. The "required" number of innings (i.e., the number of innings that must be played to constitute a full game) is typically either six (e.g., in "Little League"), seven (high school), or nine (major leagues), but, hypothetically, it could be any natural number.
During the first (or "top") half of each inning, the visiting team bats (i.e., is on offense). During the second (or "bottom") half, the home team bats. For convenience, we identify each half-inning with the team who is batting and thus refer to them as the visitor half and the home half, respectively, of the inning.
During the playing of a half-inning, the batting team's goal is to score runs3 and the defending team's goal is to make outs. When the third out of a half-inning has been made, the game proceeds to the next half-inning (except in cases where the game has come to an end). The details involved in batting, scoring runs, and making outs are extensive but are not of concern to us. (We are "abstracting them away".)
Upon completion of the required number of innings, the team that has scored the greater number of runs is declared the winner.4 However, it's not quite as simple as that, so some qualification is needed. To make things concrete, assume that we are talking about a 9-inning game (i.e., one for which the required number of innings is nine).
From these rules we can infer the existence of several baseball scenarios that often occur, including:
You are given the following "artifacts":
|
The figure below shows the output generated by the BaseballGameClient when given that sample input data. For each event code provided as input, the program shows (an encoding of) the state of the game after that event has occurred. To illustrate how the state of a game is encoded, consider as an example
This describes the state of a 9-inning game in which the home team is leading by a score of 4 runs to 2, with 1 out having been made in the Visitor's half of the 7th inning.
Enter duration of game in # innings:9 New 9-inning game... [0-0][V1,0:9] Enter event code(s) (o/r/q):oorro Recording an out ... [0-0][V1,1:9] Recording an out ... [0-0][V1,2:9] Recording a run ... [0-1][V1,2:9] Recording a run ... [0-2][V1,2:9] Recording an out ... [0-2][H1,0:9] Enter event code(s) (o/r/q):oroo Recording an out ... [0-2][H1,1:9] Recording a run ... [1-2][H1,1:9] Recording an out ... [1-2][H1,2:9] Recording an out ... [1-2][V2,0:9] Enter event code(s) (o/r/q):rooo Recording a run ... [1-3][V2,0:9] Recording an out ... [1-3][V2,1:9] Recording an out ... [1-3][V2,2:9] Recording an out ... [1-3][H2,0:9] Enter event code(s) (o/r/q):ooo Recording an out ... [1-3][H2,1:9] Recording an out ... [1-3][H2,2:9] Recording an out ... [1-3][V3,0:9] Enter event code(s) (o/r/q):ooo Recording an out ... [1-3][V3,1:9] Recording an out ... [1-3][V3,2:9] Recording an out ... [1-3][H3,0:9] Enter event code(s) (o/r/q):oq Recording an out ... [1-3][H3,1:9] Quitting ... [1-3][H3,1:9] *** Game not over Goodbye. |
You are to submit your work in two increments. For the first, the goal is to put into working order all the observer methods whose names include the word "inning" (possibly plural or capitalized). Of course, this means that any methods upon which those methods rely must also be put into working order. It also means that one or more instance variables may need to be introduced.
After completing the first increment, what should be left is to put into working order the methods that pertain to runs being scored and methods that determine whether a game is over (and, if so, who won). That is your task for the second increment.
There will be two distinct folders into which to submit your BaseballGame source code, one for each increment. The names of the folders will make obvious which increment each one refers to.
As usual, your source code should include comments that identify you, any persons with whom you collaborated, and any defects that you are aware of.
[3] Scoring a run in baseball is analogous to scoring a "point" in most other games.