Here is the whole Question. Create a class called BowlingGame. Objects of this c
ID: 3529254 • Letter: H
Question
Here is the whole Question.
Create a class called BowlingGame. Objects of this class represent a single game of bowling. Attributes of such an object include the name of the bowler, the current score and frame, and the number of strikes, spares, and gutter balls rolled so far in the game. Provide
....A constructor that accepts the name of the bowler as a String parameter.
....A transformer method called shot that accepts an int parameter indicating the number of pins knocked down on the next "shot." The shot method should return a boolean indicating whether the current frame is over for the bowler. You can assume that the shot method will only be passed integers that "make sense" within the current bowling game (e.g., it will not be passed a negative, it will not be a passed a 5 if there are only 3 pins currently standing).
....Provide Getter methods for the various attributes
....Provide a toString method that returns a nicely formatted string that summarizes the current status of the game
....Provide a "test driver" program that demonstrates that your BowlingGame class performs correctly.
I'm still early on in my coding, but this is what I have so far.
import java.util.Scanner;
public class BowlingGame
{
//instance variables
protected String name;
protected int currentScore;
protected int currentFrame;
protected int numStrikes;
protected int numSpares;
protected int numGutterBalls;
protected int NumOfPins;
//constructors
public BowlingGame()
{ //Deafult Constructor
name = ""; //sets name to null
currentScore = 0; //Sets the current Score to 0
currentFrame = 1; //Sets the current Frame to 1 as the deafult value
numStrikes = 0; //Sets the numStrikes to 0
numSpares = 0; //Sets to the Number of Spares to 0
numGutterBalls = 0; //Sets to the Number of Gutter Balls to 0
NumOfPins = 10; //Sets the Number of Pins Standing
}
public BowlingGame(String BowlerName)
{
name = BowlerName;
}
public BowlingGame( int curScore, int curFrame, int Strikes, int Spares, int GutterBalls, int NumOfPins)
{
currentScore = curScore;
currentFrame = curFrame;
numStrikes = Strikes;
numSpares = Spares;
numGutterBalls = GutterBalls;
this.NumOfPins = NumOfPins;
}
//observers(getter)
public String getName()
{
return name;
}
public int getCurrentScore()
{
return currentScore;
}
public int getCurrentFrame()
{
return currentFrame;
}
public int getStrikes()
{
return numStrikes;
}
public int getSpares()
{
return numSpares;
}
public int getGutterBalls()
{
return numGutterBalls;
}
//transformers
//other methods
public boolean shot(int numOfPinsDown)
{
if (numOfPinsDown - NumOfPins == 10)
{
return true; //Returning a True Value means that the current Frame for the Bowler is over and will move to the Next Frame
}
else if (numOfPinsDown < 10 & numOfPinsDown > 0)
{
return false; //Returning a False Value means that the current Frame is still
}
return false;
} //END METHOD SHOT
public String toString()
{
String str;
str = name + "'s game after frame"; //+ ......
return str;
} // end toString
public static void main(String[] args)
{
Scanner Bowl = new Scanner(System.in);
}
}
//end main
//End class BowlingGame
Explanation / Answer
Bowling Game
---------------------------------
import java.util.Scanner;
public class BowlingGame {
Scanner scan=new Scanner(System.in);
String name;
int currentScore;
int currentFrame;
int numStrikes;
int numSpares;
int numGutterBalls;
int NumOfPins;
public BowlingGame(String name) {
super();
this.name = name;
}
//Deafult Constructor
public BowlingGame()
{
name = ""; //sets name to null
currentScore = 0; //Sets the current Score to 0
currentFrame = 1; //Sets the current Frame to 1 as the deafult value
numStrikes = 0; //Sets the numStrikes to 0
numSpares = 0; //Sets to the Number of Spares to 0
numGutterBalls = 0; //Sets to the Number of Gutter Balls to 0
NumOfPins = 10; //Sets the Number of Pins Standing
}
public boolean shot(int numOfPinsDown)
{
if (numOfPinsDown - NumOfPins == 10)
{
return true; //Returning a True Value means that the current Frame for the Bowler is over and will move to the Next Frame
}
else if (numOfPinsDown < 10 & numOfPinsDown > 0)
{
return false; //Returning a False Value means that the current Frame is still
}
return false;
}
public String toString()
{
String str;
str = name + "'s game after frame"; //+ ......
return str;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCurrentScore() {
return currentScore;
}
public void setCurrentScore(int currentScore) {
this.currentScore = currentScore;
}
public int getCurrentFrame() {
return currentFrame;
}
public void setCurrentFrame(int currentFrame) {
this.currentFrame = currentFrame;
}
public int getNumStrikes() {
return numStrikes;
}
public void setNumStrikes(int numStrikes) {
this.numStrikes = numStrikes;
}
public int getNumSpares() {
return numSpares;
}
public void setNumSpares(int numSpares) {
this.numSpares = numSpares;
}
public int getNumGutterBalls() {
return numGutterBalls;
}
public void setNumGutterBalls(int numGutterBalls) {
this.numGutterBalls = numGutterBalls;
}
public int getNumOfPins() {
return NumOfPins;
}
public void setNumOfPins(int numOfPins) {
NumOfPins = numOfPins;
}
public static void main(String[] args)
{
BowlingGame bGame=new BowlingGame();
bGame.setName("Amit Kumar");
bGame.shot(4);
}
}
-----------------------------------------------
Or Refer this for more help
-----------------------------------------
http://www.dreamincode.net/forums/topic/32100-help-with-bowling-scoring-project/