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;
}
}
- 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started