An exercise for counting responses to a survey.
Fork and clone this repository. You can look at the instructions from our previous exercise as a reminder of how to do this. MAKE SURE TO CLONE YOUR FORK, NOT THE ORIGINAL.
There is a file responses.txt that contains the data we'll be working with. Here's what's inside it.
studentA maps
studentB maps
studentA lists
studentB arrays
studentC loops
studentC arrays
studentA compound
The first string on each line is a pseudonymous id of a student. The second string is a topic they want to know more about.
Look at Tallyer.java to see the already provided code. Take a look over it and predict what it will do when you run it.
- Open your terminal in VS Code. On Mac/Linux, it should have the right type of terminal by default. On Windows, follow these instructions to make Git Bash the default terminal. (You do not need to do step 1 because you already have installed git).
- Verify you are in the
response-tallydirectory by runningpwd(print working directory) on the terminal. The printed directory should end inresponse-tally. - Compile the Java files by running
javac src/Tallyer.java - Run the main method of Tallyer by running
java -cp src Tallyer < responses.txt - You should expect that it will say "null" for how many times each topic appears. This is because you have not completed the assignment yet. Once completed, it will show the proper tallies.
Once you have completed the below section (Modifying the Code), please open a Pull Request (PR). Please copy and paste your PR URL into Canvas to receive credit. Include your attempt at Wave 2, even if you did not complete it.
Implement tallyTopics. Read the Javadoc carefully to understand what the method is meant to do. Make sure to compile your code each time before running it!
For the sample responses.txt file, a correct output would look similar to:
{maps=2, lists=1, loops=1, arrays=2, compound=1}
The order is unimportant.
Try also running it on bigResponses.txt and see the result.
Implement tallyTopicsFiltered. Read the Javadoc carefully to understand what the method is meant to do. Make sure to compile your code each time before running it!
For the above sample file, a correct output would look similar to:
{maps=1, loops=1, arrays=2}
The order is unimportant.
Try also running it on bigResponses.txt and see the result.
Some more ways to exercise:
- Display the results in sorted order
- Robustly handle malformed files
- Come up with some other interesting way to work with the data!