Question: Given the class below: public class BasketballTeam { private int score; private String name; public BasketballTeam(String s) { score = 0; name = s; }

Given the class below:

public class BasketballTeam

{

private int score;

private String name;

public BasketballTeam(String s)

{

score = 0;

name = s;

}

public int getScore( )

{

return score;

}

public String getName( )

{

return name;

}

public String toString( )

{

return ("The " + name + " have " + score + " points. ");

}

public int freeThrow( )

{

score++;

return score;

}

public int threePoint( )

{

score += 3;

return score;

}

public int makeShot( )

{

score += 2;

return score;

}

}

  1. Consider the class BasketballTeam above. What is the output of the following demo driver program? BOX IN YOUR ANSWER

public class BigGame

{

public static void main(String[ ] args)

{

BasketballTeam team1 = new BasketballTeam("Raiders");

BasketballTeam team2 = new BasketballTeam("Tigers");

team1.makeShot( );

team2.freeThrow( );

team1.threePoint( );

System.out.println ("Team 1 has " + team1.freeThrow( ) + " points.");

team2.makeShot( );

System.out.print(team1);

System.out.print(team2);

}

}

2. Using the BasketballTeam class above, write a complete demo driver class on the next page, which simulates a basketball game in the following way:

instantiate two teams as above, and then assume the teams alternate possession of the ball

for 20 times each. During each possession (show each possession of the ball with an if-else chain), the team with the ball has the following probabilities:

  • 35% chance of making a 2-point shot
  • 15% chance of making a 3-point shot
  • 20% chance of making a free throw
  • 30% chance of turning over the ball without scoring

Use a double variable set to equal Math.random( ), together with some

if-else statements, to control the probabilities. After each possession,

print the score of both teams to the screen.

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!