forked from stjpm09/ClassMelee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClansWins.java
executable file
·40 lines (34 loc) · 1.13 KB
/
ClansWins.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
package clanmelee;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class ClansWins {
private HashMap<Integer, ClanWins> clansWins = new HashMap<>();
private int maxNameWidth = 0;
public int clanCount() {
return clansWins.size();
}
public void addClan(int clanID, String clanName) {
clansWins.put(clanID, new ClanWins(clanName));
if (clanName.length() > maxNameWidth)
maxNameWidth = clanName.length();
}
public void addWin(int victorID) {
clansWins.get(victorID).addWin();
}
public void print() {
ArrayList<ClanWins> arrayWins = new ArrayList<>();
arrayWins.addAll(clansWins.values());
Collections.sort(arrayWins);
String line = "+";
for (int i = 0; i < maxNameWidth + 6; i++)
line += "-";
line += "+";
System.out.println(line);
for (ClanWins wins : arrayWins) {
System.out.println(String.format("| %" + maxNameWidth + "s: %-3s|",
wins.getName(), wins.getWins()));
}
System.out.println(line);
}
}