forked from get-flord/Project2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTotalWinsOfClans.java
More file actions
executable file
·61 lines (54 loc) · 1.89 KB
/
TotalWinsOfClans.java
File metadata and controls
executable file
·61 lines (54 loc) · 1.89 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
package clanmelee;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
/**
* This class creates a hashmap of clans with their unique ID as the key
* and the name of the clan as the value.
*/
public class TotalWinsOfClans {
private HashMap<Integer, ClanWins> totalWinsOfClans = new HashMap<Integer, ClanWins>();
private int maxNameWidth = 0;
/**
*
* @return int - the number of clans in the HashMap
*/
public int clanCount() {
return totalWinsOfClans.size();
}
/**
* Adds a clan to the HashMap
* @param clanID - integer ID number for the clan being added
* @param clanName - name of the clan that is being created
*/
public void addClan(int clanID, String clanName) {
totalWinsOfClans.put(clanID, new ClanWins(clanName));
if (clanName.length() > maxNameWidth)
maxNameWidth = clanName.length();
}
/**
* Adds a win to the number of wins for a victorious clan
* @param victorID - integer ID of the winning clan
*/
public void addWin(int victorID) {
totalWinsOfClans.get(victorID).addWin();
}
/**
* Prints out the name of each clan and its corresponding number of wins
*/
public void print() {
ArrayList<ClanWins> arrayWins = new ArrayList<ClanWins>();
arrayWins.addAll(totalWinsOfClans.values());
Collections.sort(arrayWins);
String line = "+";
for (int i = 0; i < maxNameWidth + 6; i++) // creates box around the clans in the round
line += "-";
line += "+";
System.out.println(line);
for (ClanWins wins : arrayWins) {
System.out.println(String.format("| %" + maxNameWidth + "s: %-3s|",
wins.getName(), wins.getWins())); //prints the clan with its corresponding number of wins
}
System.out.println(line);
}
}