/
Manipulation.java
43 lines (38 loc) · 1.22 KB
/
Manipulation.java
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
import java.util.ArrayList;
/**
* Created by Bobby Gupta on 1/21/2017.
*/
public class Manipulation extends Variables {
public void addParticipant (String email, int bet) {
participants.put(email, bet);
emails.add(email);
pair(email, bet);
}
public void pair (String email, int bet) {
if (participants.size() >= 2) {
int finalBet = 0;
int betPlayer1 = participants.get(emails.get(0));
int betPlayer2 = participants.get(emails.get(1));
if (betPlayer1 <= betPlayer2) {
finalBet = betPlayer1;
} else {
finalBet = betPlayer2;
}
while (true) {
try {
bets.get(finalBet);
finalBet++;
} catch (Exception e) {
break;
}
}
bets.put(finalBet, new ArrayList<String>());
bets.get(finalBet).add(emails.get(0));
bets.get(finalBet).add(emails.get(1));
emails.remove(0);
emails.remove(0);
participants.remove(0);
participants.remove(0);
}
}
}