-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
50 lines (41 loc) · 2.33 KB
/
Main.java
File metadata and controls
50 lines (41 loc) · 2.33 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class Main {
public static void main(String[] args) {
int numOfParticipants = 100;
List<Participant> participantsList = new ArrayList<>(numOfParticipants);
List<Participant> winnersList = new ArrayList<>();
List<Participant> loserList = new ArrayList<>();
//this loop creates our contestants with unique names
for (int i = 0; i < numOfParticipants; i++) {
participantsList.add(new Participant());
}
int flipRound = 1; //keeps track of the rounds after each person flips a coin
while (participantsList.size() != 1) {//the loop where each person flips a coin determining who sits or stays in the game
System.out.println();
System.out.println("Beginning round " + flipRound);
System.out.println("1 = heads, 2 = tails");
for (int i = 0; i < participantsList.size(); i++) {
int number = Participant.coinFlip();
System.out.println("coin flip was " + number);
if (number == 2) {
System.out.println(participantsList.get(i).getName() + " got " + number + " they will now sit down");
loserList.add(participantsList.get(i));
participantsList.remove(i);
} else {
participantsList.get(i).setHeadsCount();
winnersList.add(participantsList.get(i));
System.out.println(participantsList.get(i).getName() + " has flipped heads, they keep standing");
}
}
System.out.println("The list of participants are: " + Arrays.asList(participantsList));
if (participantsList.size() == 1) {
System.out.println("We have a winner! " + participantsList.get(0).getName() + "! They flipped heads " + participantsList.get(0).getHeadsCount() + " consecutive times");
}
// System.out.println("The List of Winners are: " + Arrays.asList(winnersList));
// System.out.println("The list of Losers are: " + Arrays.asList(loserList));
flipRound++;
}
}
}