-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSc2310_MyNBATeam.java
More file actions
104 lines (69 loc) · 2.12 KB
/
CSc2310_MyNBATeam.java
File metadata and controls
104 lines (69 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
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
public class MyNBATeam {
private String sTeamName;
private int nWin;
private int nLoss;
//private String[] playerArray; //need to know the size of this array before it can be used. ArrayList<String> used because array size was not provided
public ArrayList<String> playerNames = new ArrayList<String>();
public MyNBATeam(String TeamName){
sTeamName = TeamName;
}
public void addAPlayer(MyNBATeam team, String yesNo, Scanner input){
while (yesNo.equalsIgnoreCase("yes")){
System.out.print("What is the name to be added? ");
playerNames.add(input.next());
System.out.print("Add one more play to " + team +"? (yes/no): ");
yesNo = input.next();
}
}
public void printResult(MyNBATeam team, int wins, int loss) {
System.out.print(team.sTeamName + team.playerNames + " Win#: " + wins + ", Loss#: " + loss +"\n");
}
public void playGame(MyNBATeam a, MyNBATeam b){
String teamA = a.sTeamName.toString();
String teamB = b.sTeamName.toString();
int teamBWin = 0;
int teamBLoss = 0;
System.out.println("\nGame on Now....\n");
do{
Random rand = new Random();
int series = rand.nextInt(11)+4;
teamBWin = 0;
teamBLoss = 0;
for(int i = 0; i < series; i ++){
double winner = rand.nextDouble()+0.0;
if(winner <= 0.5){
nWin++;
teamBLoss++;
}
else if(winner > 0.5){
teamBWin++;
nLoss++;
}
if(nWin >= 4){
System.out.println(teamA +" ***WIN the series***");
break;
}
else if(teamBWin >= 4){
System.out.println(teamB + " ***WIN the series***");
break;
}
}
}while(nWin < 4 && teamBWin < 4);
printResult(a, nWin, nLoss);
printResult(b, teamBWin, teamBLoss);
}
public void winSeries(String teamA, String teamB, int teamAWin, int teamBWin){
if(teamAWin >= 4){
System.out.println(teamA +" ***WIN the series***");
}
else if(teamBWin >= 4){
System.out.println(teamB + " ***WIN the series***");
}
}
public String toString(){
return ""+this.sTeamName;
}
}