Lab: The One Style in Java
The One style in Java - Introduction
In this lab you will implement a solution of the The One style in Java for the term frequency task.
(The unchanged task description is available in the Prelude of the first lab.)
The constraints of the The One style (including the ⚠️ WARNING ⚠️) are the same as the ones specified in the previous lab.
The goal of this lab is to write code that follows (a clean version of) this style.
Unlike the previous lab, this one requires you to think about types. You might realize that the type checker actually helps you in verifying that your solution adheres to the style.
Use “strong types”:
you should avoid circumventing the type checker (e.g., avoid casts and avoid Object
as a type).
Create and Clone Your GitHub Repository
To create the repository for this lab, fork this starter repository.
Your repository now exists on the GitHub servers. If you want to work on it, you first have to “clone” it on your computer.
Implement Your Program
You can find Crista’s Python implementation of the Term Frequency task in The One style in her GitHub repository:
https://github.com/crista/exercises-in-programming-style/blob/master/10-the-one/tf-10.py
If you want, you can use Crista’s implementation as a starting point for your Java code (but be mindful of the aspects described in the warning). You can also make use of the functions’ implementations you wrote for the JavaScript Pipeline lab (or the code snippets provided in the description of that lab).
Once you have the repository (a directory) on your computer,
you can open it in your IDE (e.g., in VS Code).
You can easily do this using the code
command, passing as an argument the path to the appropriate directory:
code ~/lab-06-theone-java
Before you start “hacking”, please read the README (file README.md
).
Then create a new Java file named TermFrequency.java
.
Implement a solution to the term frequency task in Java following the The One style.
Run, Test, and Debug the Program
Read the README.md
and the first part of this lab to figure out how to run the program.
Test
We strongly recommend to use the test script, because it shows you whether your solution is functionally correct. For this, it compares your output with the reference output we provided. Obviously, this only works if you strictly follow the rules (e.g., don’t print out debug output), otherwise the script will tell you that you don’t produce the correct output.