Question: public class BasketballTeam { private int score; private String name; public BasketballTeam(String s) { score = 0; name = s; } public int getScore( )
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;
}
}
2
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
Get step-by-step solutions from verified subject matter experts
