diff --git a/src/Main.java b/src/Main.java index 8d40cbf..1a3a7b7 100644 --- a/src/Main.java +++ b/src/Main.java @@ -8,12 +8,13 @@ public class Main { // Gets a map with the total occurrences for each domain Map domains = getDomainTotal(data); - System.out.println(domains); - // Order the map by descending value of the value List> 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; } + + /** + * 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> domains) { + StringBuilder output = new StringBuilder(); + for (Map.Entry 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(); + } } \ No newline at end of file