Question: Given are the partial java source codes for NBATeam and NBA classes. NBATeam class is the class for a basketball team. The class sets the

Given are the partial java source codes for NBATeam and NBA classes. NBATeam class is the class for a basketball team. The class sets the name of the team and assigns members name (name is input by the user). NBA class creates two teams Heats and Spurs using NBATeam class. It asks for the number of players in each team, then asks the name of the members. Members are added to the respective team using addAPlayer(String newPlayerName) method in NBATeam class. Write the code for the method addAPlayer(String newPlayerName)in NBATeam class. You may also create other supporting methods which you think might we required.

After adding the team players, the NBA class will simulate a game series between Heats and Spurs. The series will have 7 games and each game is a random play. For each game, you need to generate a random number, if the random number is bigger than 0.5, Heat wins; otherwise Heat losses a game. As soon as one of the team wins 4 games, the series is over. Announce who wins game along with the player names in each team and the score of each team. Write code to simulate this game play in NBA class.

Finish the programs for both classes to produce an output screen similar to the following figure.

How many players Heats own: 5

Enter the name of Player #1: Heats1

Enter the name of Player #2: Heats2

Enter the name of Player #3: Heats3

Enter the name of Player #4: Heats4

Enter the name of Player #5: Heats5

How many players Spurs own: 5

Enter the name of Player #1: Spurs1

Enter the name of Player #2: Spurs2

Enter the name of Player #3: Spurs3

Enter the name of Player #4: Spurs4

Enter the name of Player #5: Spurs5

Spurs ***WIN the series***

Heats[ Heats1 Heats2 Heats3 Heats4 Heats5 ] win #: 3 los : 4

Spurs[ Spurs1 Spurs2 Spurs3 Spurs4 Spurs5 ] win #: 4 los : 3

GIVEN CODE

//NBATeam

public class NBATeam {

private String sTeamName;

private int nWin;

private int nLoss;

private String [] playerArray;

//Your code here

}//end of class definition

//NBA

//Warning: Do not change the given codes

import java.util.Scanner;

public class NBA {

public static void main(String[] args) {

//construct Team Heat

NBATeam heat= new NBATeam("Heats");

System.out.print("How many players Heats own: ");

Scanner input = new Scanner (System.in);

int numberOfPlayers = input.nextInt();

// Prompt user to enter players into the Team

for (int i = 0; i < numberOfPlayers; i++) {

System.out.print("Enter the name of Player #" + (i + 1) + ": ");

String playerName = input.next();

heat.addAPlayer(playerName);

}

//construct Team Spurs

//Your code here

/*simulate a series of atmost 7 games by generating a random number;

* if the random number is bigger than 0.5, Heat wins; otherwise Heat losses a game.

* As soon as team wins 4 games, the series is over. */

//Your code here

System.out.println(heat);

System.out.println(spurs);

}

}

}

}

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!