-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSc2310_NBATeam.java
More file actions
105 lines (82 loc) · 2.12 KB
/
CSc2310_NBATeam.java
File metadata and controls
105 lines (82 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import java.util.ArrayList;
import java.util.Random;
//Stephanie Wyckoff
//7/10/2016
//NBATeam
//Set up for NBA teams, player names and game play mode. Stores team information and game win/lose record and prints for the user.
public class NBATeam {
private String sTeamName;
private int nWin;
private int nLoss;
private String[] playerArray = new String[50];
private ArrayList<String> playerList = new ArrayList<String>();
public NBATeam(String TeamName){
sTeamName = TeamName;
setUpList();
}
private void setUpList(){ //fills in player array when new NBATeam is created; ensures zero null elements
for(int i = 0; i < playerArray.length; i++){
playerArray[i] = "-";
}
}
public void addAPlayer(String playerName){ //adds player names from user input to array
for(int i = 0; i < playerArray.length; i++){
if(playerArray[i] == "-"){
playerArray[i] = playerName;
if(playerArray[i+1] == "-"){
break;
}
}
}
}
public ArrayList<String> getPlayerList(){ //allows only the elements with user input to print out
for(int i = 0; i < playerArray.length; i++){
if(playerArray[i] != "-"){
playerList.add(playerArray[i]);
}
}
return playerList;
}
public String getTeamName(){
return sTeamName;
}
public int getWins(){
return nWin;
}
public int getLoss(){
return nLoss;
}
public void playGame(NBATeam a, NBATeam b){
String teamA = a.sTeamName.toString();
String teamB = b.sTeamName.toString();
System.out.println("\nGame on Now....\n");
do{
Random rand = new Random();
int series = rand.nextInt(11)+4;
a.nWin = 0;
b.nLoss = 0;
for(int i = 0; i < series; i ++){
double winner = rand.nextDouble()+0.0;
if(winner <= 0.5){
a.nWin++;
b.nLoss++;
}
else if(winner > 0.5){
b.nWin++;
a.nLoss++;
}
if(a.nWin >= 4){
System.out.println(teamA +" ***WIN the series***");
break;
}
else if(b.nWin >= 4){
System.out.println(teamB + " ***WIN the series***");
break;
}
}
}while(a.nWin < 4 && b.nWin < 4);
}
public String toString(){
return ""+this.sTeamName;
}
}