mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2025-05-18 15:24:15 +02:00
feat: add output format for the data
This commit is contained in:
parent
75f5785297
commit
cd68d30e6d
@ -8,12 +8,13 @@ public class Main {
|
|||||||
// Gets a map with the total occurrences for each domain
|
// Gets a map with the total occurrences for each domain
|
||||||
Map<String, Integer> domains = getDomainTotal(data);
|
Map<String, Integer> domains = getDomainTotal(data);
|
||||||
|
|
||||||
System.out.println(domains);
|
|
||||||
|
|
||||||
// Order the map by descending value of the value
|
// Order the map by descending value of the value
|
||||||
List<Map.Entry<String, Integer>> sortedDomains = sortDomainMapDesc(domains);
|
List<Map.Entry<String, Integer>> sortedDomains = sortDomainMapDesc(domains);
|
||||||
|
|
||||||
System.out.println(sortedDomains);
|
// Format the data to the format specified
|
||||||
|
String output = domainListToString(sortedDomains);
|
||||||
|
|
||||||
|
System.out.println(output);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -62,4 +63,25 @@ public class Main {
|
|||||||
|
|
||||||
return sortedDomains;
|
return sortedDomains;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a string in a format to display the data from a list of domains and their occurrences.
|
||||||
|
* @param domains A list of all the domains and their occurrences
|
||||||
|
* @return A string with a specific format
|
||||||
|
*/
|
||||||
|
private static String domainListToString(List<Map.Entry<String, Integer>> domains) {
|
||||||
|
StringBuilder output = new StringBuilder();
|
||||||
|
for (Map.Entry<String, Integer> entry : domains) {
|
||||||
|
// Get the values of the entry
|
||||||
|
String domain = entry.getKey();
|
||||||
|
Integer occurrences = entry.getValue();
|
||||||
|
|
||||||
|
output.append(domain).append(" ").append(occurrences).append("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove unnecessary \n at the end of the output
|
||||||
|
output.deleteCharAt(output.length() - 1);
|
||||||
|
|
||||||
|
return output.toString();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user