Methods:
Homework #7 A Simple Game of Bowling (60 points)
Important: Whenever a "player ID number" is brought up, the indices of the array
1. A standard accessor function for 'numberOfPlayers' called
directly correspond to each player's ID number. For example, player number
Note: Make sure both class names are spelled EXACTLY as shown below. Neither
"getNumberOfPlayers" (has capital letters 'N', 'oh', and 'P').
one's ID number is zero. Player number two's ID number is one, etc.
of the 'B' letters should be lowercase and the underscore between the words
Note: No need for a mutator method, but if you create one anyway,
"Bowling" and "Game" is a part of the second class' name.
that's fine. Just make sure the rest of your code works like normal.
Note: Everything in class 'Bowler' must be public and non-static. For class
Important: Unless stated otherwise, you do NOT need to check the validity of any
'Bowling Game', its attributes must be private while its constructors / functions
of these functions' parameters. For example:
2. An accessor function called "getPlayerHandicap" (first 'P' is capitalized,
are public (and all of its attributes and functions are all non-static).
and so is the 'H' letter) which has ONE integer parameter.
If a function's parameter is meant to represent a player ID number, you can
The parameter value represents a player's ID number, and so, this
Also, make sure the names for all of the functions and all of the
assume that it' II always be non-negative and that it'll be less than the
function must simply return that particular player's handicap value.
non-parameter variables are spelled out exactly as shown below.
game's total number of players.
3. A mutator function called "setPlayerHandicap" (first 'P' is capitalized,
Define a class called 'Bowler' with the following characteristics:
and so is the 'H' letter) which has TWO integer parameters.
Define a class called 'Bowling Game' with the following characteristics:
The first integer parameter value represents a player's ID number,
Attributes:
Attributes:
and so, this function must simply assign the second parameter's
An integer array called 'frameScores' (the first 'S' is capitalized).
An integer called 'numberOfPlayers' (with a capital 'oh' and capital 'P').
value into the array's corresponding player's handicap attribute.
Note: The frame score at index zero will be called "Frame #1",
An array of 'Bowler's called 'players'.
Note: Can assume handicap argument will always be positive.
the frame score at index one will be called "Frame #2", etc.
An integer called 'handicap'.
Constructors:
4. An accessor function called "getPlayerScore" (with a capital 'P' and 'S')
A default constructor which initializes 'numberOfPlayers' to one.
which has ONE integer parameter.
Constructors:
A constructor with one integer parameter. Said parameter's value is to
The parameter value represents a player's ID number, and so, this
A default constructor which initializes 'handicap' to zero.
be assigned into 'numberOfPlayers'
function must simply return that particular player's total score
Must also define the 'frameScores' array to be of length ten.
Note: We'll assume it's always between one and four (inclusive).
(with the handicap applied).
Note: No need to manually initialize its elements since they
Tip: Utilize the first "getScore" function from class 'Bowler'.
should already be zero automatically.
Important: Not only must both constructors define the 'players' array
5. Overload the "getPlayerScore" function so that it now has TWO
Methods:
(whose size is directly proportional to the number of players), both
parameters (and the same return type).
constructors must propagate said array with [new] objects based on class
function called "getScore" (with a capital 'S') which has no parameters
First parameter is an integer and represents a player's ID number.
'Bowler's default constructor.
and an 'int' return type.
Second parameter is a boolean.
Will add up (and return) all values in 'frameScores', plus the
Once again, the number of instantiations assignments should be
If the boolean value is true, return the same value that the
'handicap' value.
dependent on the number of players. One for one, two for two, etc.
original "getPlayerScore" function would return, otherwise
If the boolean value is false, return the given player's score but
Overload the "getScore" function so that it now has boolean parameter
with the handicap value omitted.
(and the same return type).
Tip: Utilize the second "getScore" function from class 'Bowler'.
If the parameter value is true, return the same value that the original
"getScore" function would return, otherwise
If the parameter value is false, just add up (and return) all values in
'frameScores'. The handicap value must be omitted in this case.
6. A function called "setOneFrameScore" with THREE integer parameters.
Note: Class 'Bowler' is worth 15 points while class 'Bowling Game' is worth 45.
10. A function called "displayOnePlayerScore" with ONE integer parameter.
Note: Return type is void and the identifier uses capital 'oh' for
Note: Return type is void and the identifier uses capital 'oh' for
"One", capital 'F' for "Frame", and capital 'S' for "score".
"One", capital 'P' for "Player", and capital 'S' for "score".
Note: Class 'Bowler' does NOT need to create any accessor or mutator functions
The parameter value represents a player's ID number.
The first parameter represents a player's ID number.
for itself, but if you want to create them (for 'handicap' specifically), that's fine.
When invoked, this function will print out all information about the
The second parameter represents a particular frame number
given player. The format of the text and output can be whatever style
(between, and including, one and ten).
you'd like, so long as all of the following information is presented:
The third parameter represents a (presumably positive) score.
Note: Aside from the constructors, the "numberOfPlayers' attribute is really only
The player's ID number (or their order in the game).
When invoked, this function must change the corresponding player's
relevant to the "winningPlayer", "winningPlayerScore", and "displayAllScores"
The player's handicap value.
corresponding frame's score to be whatever value the new score is.
functions. All three of these functions must not deal with non-existent players.
All ten of their frame scores.
For example, if the function call is "setOneFrameScore(1, 2, 3);",
For example, if there's only two players, the "displayAllScores" function
then Player #2 (at index one) needs to have its second frame
The total score WITH the handicap applied.
must not print out anything about Players #3 and #4 (just players 1 and 2).
score (at index one) be assigned the value of three.
The total score WITHOUT the handicap applied.
Note: If handicap is zero, printing the score just once will do.
7. A void function called "setAllFrameScores" with TWO parameters:
Visual Aid: See last page for an example.
Note: If you want to implement class 'Bowling Game' so that maximum four
the first an integer, the second an integer array.
player cap does NOT exist, that's fine. Just make sure that the rest of your
Note: Can assume the array argument's size is always exactly ten.
11. A void function called "displayAllScores" with no parameters.
functions work with this in mind.
The first parameter value represents a player's ID number, and so,
Same thing as the "displayOnePlayerScore" function but now does so
For example, if there's ten players, then the "displayAllScores" function
this function will simply assign all the values from within the array
for every single player (again, see last page for an example).
must output all ten players' stats.
parameter into the player's corresponding frame scores.
The first integer element will be used for Frame #1 (at index zero),
the second integer value will be used for Frame #2 (at index one),
Hint: The solutions for the two "winningPlayer" functions doesn't need to be tha
etc.
complicated. Each one can be solved with one loop (going through all bowlers)
with the first bowler being set as the default winning player. A single if statement
8. A function, with an integer return type, called "winningPlayer"
can be used to change the winning ID number when a new player's score is
(spelled with a capital 'P') which has NO parameters.
greater than the current winning player's score.
Comparing all the current total scores (with handicaps applied)
The "winningPlayerScore" function could alternatively simply utilize the
amongst all active players, this function must return the ID number
"winningPlayer" function so that it hardly has to do anything for itself.
of whichever player has the highest score.
Return zero for Player #1, return one for Player #2, etc.
Note: If two or more players are tied, any one of their IDs will do.
Tip: Most functions in class 'Bowling Game' could I
of code (assuming we don't count the function hea
9. A function, with an integen return type, called "winningPlayerScore"
(spelled with a capital 'P' and 'S') which has NO parameters.
In particular, both constructors and functions
Does the same thing as function "winningPlayer" but will instead
"getPlayerHandicap", "setPlayerHandicap",
return said player's total score (with the handicap applied).
versions), "setOneFrameScore", and possibly
*******