Question: Main Code: public class BowlingGame { private String name; private int[][] scores = new int[10][3]; private int strikes; private int spares; private int frame; private

Main Code: public class BowlingGame { private String name; private int[][] scores= new int[10][3]; private int strikes; private int spares; private int frame;Main Code:

public class BowlingGame {

private String name;

private int[][] scores = new int[10][3];

private int strikes;

private int spares;

private int frame;

private int shot;

private int gutterBalls;

private int score;

private static final char tempScoreValue = 'N';

private static final int maxNumFrames = 10;

private static final int maxNumShots = 3;

public BowlingGame(String n){

name = n;

for(int i = 0; i

for(int j = 0; j

scores[i][j] = 0;

}

}

strikes = 0;

spares = 0;

gutterBalls = 0;

score = 0;

frame = 0;

shot = 0;

}

public boolean shot(int p){ //return false if the frame is over.

boolean nextShot = false;

if(p == 10){

if(shot == 0)

strikes++;

//your code goes here!

if(shot == 1)

spares++;

}

else{

//your code goes here!

}

frame++;

return nextShot;

}

public int getFrame(){

return frame;

}

public String toString(){

return name + "'s game after frame " + frame + ": Strikes " + strikes

+ ", Spares " + spares + ", Gutter Balls " + gutterBalls + ", Score " + score;

}

public void computeScoreFrame(){

int f = getFrame()-1;

if(f >=2){ //look two frames back

//your algorithm for the bonus points goes here.

}

else if(f == 1){ //look one frame back

//your algorithm for the bonus points goes here.

}

else{ //first frame

score += scores[f][0] + scores[f][1];

}

}

public int getScore(){

return score;

}

}

Driver:

import javax.swing.JOptionPane;

public class BowlingGameDriver{

public static void main(String[] args) {

String n = JOptionPane.showInputDialog("Please enter a name for a bowler: ");

BowlingGame g = new BowlingGame(n);

int scores1[][] = { {5, 5}, {3, 7}, {0, 0}, {4, 6}, {10, 0}, {1, 9}, {10, 0},

{8, 1}, {0, 10}, {10, 0, 10}

};

int scores2[][] = { {5, 5}, {3, 7}, {0, 0}, {4, 6}, {10, 0}, {1, 9}, {10, 0},

{8, 1}, {0, 10}, {0, 10, 10}

};

int scores3[][] = { {2, 6}, {10, 0}, {10, 0}, {5, 5}, {2, 0}, {7, 1}, {10, 0},

{10, 0}, {5, 5}, {10, 3, 5}

};

int pins, i = 0, j;

while(g.getFrame()

j = 0;

do{

//pins = Integer.parseInt(JOptionPane.showInputDialog("Enter the pins knocked over for frame " + (g.getFrame()+1) + " :"));

pins = scores1[i][j];

j++;

}while(g.shot(pins));

i++;

//g.computeScoreFrame();

JOptionPane.showMessageDialog(null, g);

}

JOptionPane.showMessageDialog(null, "The bowler's score is: " + g.getScore());

}

}

a) First create the BowlingGame class. Objects of this class represent a single game of bowling for a given player. A BowlingGame object should maintain the player's name, current score and frame, anda count of strikes, spares, and gutter balls, etc. The provided files are already set up with the data members, and methods: constructor, toString, getFrame and getScore for the BowlingGame object. In order to complete the Exercise, the shot method needs to be implemented and tested. The shot method takes an int as a parameter and returns a boolean value depending on whether or not there is another shot available in a given frame. If there is not a shot left, the method will return false. Assume the shot method is only given valid input that holds true to the rules of bowling. For example, if we are in the first frame, the shot method will return true if the first value is a 5 and then return false after the next value for that frame. However, if the first shot of a frame is a 10, then the shot method will return false for the second shot (unless it is the 10th frame). The shot method will maintain the scores for each frame, the count of: strikes, spares, and gutterballs, the frame, and the shot for the frame. Remember, the 10th frame does allow a third shot if there is a strike or spare amongst the first two shots. If a player gets a strike on the first shot of the 10th frame and then a gutter ball, the player still gets a third shot. Keep in mind, you are not keeping track of the actual score frame-by-frame, yet

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!