Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IT FINALLY WORKS #19

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/Tallyer.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.*;

/**
* The Tallyer class provides functionality for reading ID and topic pairs from user input,
Expand All @@ -17,6 +14,7 @@ public class Tallyer {
* @param args command-line arguments (not used in this implementation)
*/
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

List<String> ids = new ArrayList<>();
Expand All @@ -32,13 +30,14 @@ public static void main(String[] args) {

// Wave 1
Map<String, Integer> topicCounts = tallyTopics(topics);

System.out.println("Here are how many times each topic appears (unfiltered):");
System.out.println(topicCounts);

// Wave 2
Map<String, Integer> topicCountsFiltered = tallyTopicsFiltered(ids, topics);
System.out.println("Here are how many times each topic appears (filtered):");
System.out.println(topicCountsFiltered);
//Map<String, Integer> topicCountsFiltered = tallyTopicsFiltered(ids, topics);
// System.out.println("Here are how many times each topic appears (filtered):");
// System.out.println(topicCountsFiltered);
}

/**
Expand All @@ -53,13 +52,23 @@ public static void main(String[] args) {
public static Map<String, Integer> tallyTopics(List<String> topics) {
// WAVE 1
// TODO: Remove the print statements and implement this method
Map<String, Integer> topicCounts = new HashMap<>();

for (String topic : topics) {
System.out.println("The topic is: " + topic);
if(topicCounts.containsKey(topic)) {
// we are overriding the existing topic and adding one to the value
topicCounts.put(topic, topicCounts.get(topic) + 1);
} else{
// If it doesn't exist than put it in the map
topicCounts.put(topic, 1);
}
}

return null;
return topicCounts;
}



/**
* Tally the occurrences of each topic from the provided lists of IDs and topics.
* This method takes two lists, one of IDs and one of topics, and returns a map
Expand Down