-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTournament.java
136 lines (126 loc) · 3.5 KB
/
Tournament.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.petdananajavi;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Generated;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
/**
* Schema for input JSON file for 5 dana na Javi competition.
*
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
@Generated("org.jsonschema2pojo")
@JsonPropertyOrder({
"players"
})
public class Tournament {
/**
*
* (Required)
*
*/
@JsonProperty("players")
private List<Player> players = new ArrayList<Player>();
@JsonIgnore
private Map<String, Object> additionalProperties = new HashMap<String, Object>();
/**
*
* (Required)
*
* @return
* The players
*/
@JsonProperty("players")
public List<Player> getPlayers() {
return players;
}
/**
*
* (Required)
*
* @param players
* The players
*/
@JsonProperty("players")
public void setPlayers(List<Player> players) {
this.players = players;
}
public void printPlayers() {
for (Player p : players) {
StringBuilder s = new StringBuilder();
s.append(p.getFirstname()).append(" ").append(p.getLastname()).append("(").append(p.getPos()).append(") ").append(" - ").append(p.calculatePlayerStats());
System.out.println(s.toString());
}
System.out.print("MVP: ");
System.out.println(getMVP().getFirstname());
}
public Player getMVP() {
int localMax = -1;
int temp = -1;
Player MVP = null;
for (Player p : players) {
temp = p.calculatePlayerStats();
if (localMax < temp) {
localMax = temp;
MVP = p;
}
}
return MVP;
}
public Player getBestForPosition(String pos, List<Player> plyrs) {
int localMax = -1;
int temp = -1;
Player DTMember = null;
for (Player p : plyrs) {
List<String> playerPositions = p.getPos();
for (String ps : playerPositions) {
if (ps.equals(pos)) {
temp = p.calculatePlayerStats();
if (localMax < temp) {
localMax = temp;
DTMember = p;
}
}
}
}
return DTMember;
}
public List<Player> getDreamTeam() {
List<Player> dreamTeam = new ArrayList<Player>();
List<String> teamList = new ArrayList<String>();
Player candidate = null;
String[] positions = {"PG", "SG", "SF", "PF", "C"};
System.out.println("Dream team: ");
for (String s : positions) {
List<Player> tmpPlayers = new ArrayList<Player>();
tmpPlayers.addAll(players);
while(tmpPlayers.size() > 0) {
candidate = getBestForPosition(s, tmpPlayers);
if (candidate == null) break;
if (!candidate.inTeam(teamList)) {
dreamTeam.add(candidate);
teamList.add(candidate.getTeam());
break;
}
else {
tmpPlayers.remove(candidate);
}
}
}
return dreamTeam;
}
@JsonAnyGetter
public Map<String, Object> getAdditionalProperties() {
return this.additionalProperties;
}
@JsonAnySetter
public void setAdditionalProperty(String name, Object value) {
this.additionalProperties.put(name, value);
}
}