Skip to content
Public template

About

Java Koans for the FRC is an interactive, step by step, course to teach Java to students engaged in the First Robotics Competition

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

190 Commits

Folders and files

Repository files navigation

Assignment: Java Koans for FRC

In this assignment you learn the Java you need to start programming an FRC robot. You work through a series of small exercises called koans. Each koan gives you a goal, some tips, and the output it expects, and tells you right away whether your code is correct. You do not need any programming experience.

The course does not cover all of Java. It covers the fundamentals you need before you start on robot code.

What you will do

  1. Set up your copy of the course.
  2. Solve the koans, one series at a time, in order.
  3. Submit each series when you finish it.
  4. Check your results on GitHub.

What you need

  • A GitHub account.
  • The assignment link from your mentor.
  • A web browser. You do not install anything on your computer.

Part 1: Set up

  1. Open the assignment link from your mentor and accept the assignment. GitHub creates your own copy of the course as a repo in the itrt4176 organization.
  2. Open your repo in Tiger Code by going to https://itrt.dev/itrt4176/<your repo name>. Replace <your repo name> with the name of the repo GitHub just created.

Tiger Code opens a code editor in your browser. You do all your work there.

Part 2: Solve your first koan

This part walks you through the first koan step by step. After it, you solve the rest on your own the same way.

The screenshots below come from an older version of VS Code. Your editor may look slightly different, but the menus and panels are in the same places.

Step 1: Run the koans

When the editor opens, you see something like this:

Editor with the koans opened

Expand the src folder. Right-click src/main/java/EnglishPathToEnlightment.java and choose Run Java:

Run Java

A terminal opens at the bottom of the editor and runs the koans. The editor prints some cryptic text first; ignore it. Look for this part:

First result

The koan master is telling you four things:

First result, commented

  • The series you are on: AboutConsoleAndVariables.
  • The koan you have not completed yet: Displaying some text in the console. You have not started, so this is expected.
  • A Console box. It shows what your code printed. It is empty for now.
  • The file where the koan lives: src/main/java/koans/english/AboutConsoleAndVariables.java.

Step 2: Open the koan file

Open src/main/java/koans/english/AboutConsoleAndVariables.java:

open src/main/java/koans/english/AboutConsoleAndVariables.java

The file has four parts. You only write code in the last one.

The imports. The first lines tell Java which other files this one needs:

package koans.english;

import static engine.Helpers.readLine;

Ignore these for now. You will understand them by the end of the course.

The class. Next comes this line:

public class AboutConsoleAndVariables {

It creates a class named AboutConsoleAndVariables. Java organizes all code into classes; think of a class as a drawer that holds related code. A file holds one class, and the file is named after it, which is why this file is AboutConsoleAndVariables.java. Everything in the class sits between the opening { here and the closing } at the bottom of the file.

Java always uses { and } to group code. Everything between a pair of curly brackets belongs to the same thing.

The koan instructions. Next is a block of green text:

    /**
     * # Displaying some text in the console
     *
     * Display 'Hello!' in the console.
     *
     * ---------   TIPS --------------
     *
     * All lines of code in Java must end with the ';' character. Ex:
     *
     *      System.out.println("Apple");
     *
     * You can use the method System.out.println([some value]) to display a value in the console.
     *
     * You can tell Java that some value is text by enclosing it between double quotes. Ex:
     *
     *      "This is text"
     *
     * -------------------------------
     *
     * Expected result in the console:
     *
     * Hello!
     *
     */

This is a comment. Java ignores everything between /* and */, so programmers use comments to explain their code. The master uses them to give you each koan's instructions. Every koan's comment has the same layout:

  • Title: # Displaying some text in the console.
  • Goal: Display 'Hello!' in the console. The console is the simplest way for a program to talk to you: it prints text in the terminal, in the Console box you saw in Step 1.
  • Tips: how to reach the goal. Square brackets, as in [some value], mark a placeholder. Replace the whole placeholder, brackets included, with your own value.
  • Expected result: exactly what your code must print.

Read all of it before you start typing. The tips usually contain everything you need.

The koan method. Last comes the place where you write code:

    public static void sayHelloInConsole() {

    }

This is a method, a named mini-program. Ignore public static void for now. sayHelloInConsole is the method's name, and the () after it tells Java it is a method. Your code goes between { and }, and nowhere else. Code outside a method's curly brackets causes an error.

Step 3: Write your answer

Use the tips one at a time.

The first tip says every line of code ends with ;. Start with that:

    public static void sayHelloInConsole() {
        ;
    }

The second tip says System.out.println([some value]) prints a value. Add it, leaving the value out for now:

    public static void sayHelloInConsole() {
        System.out.println();
    }

The third tip says text goes between double quotes. Put the text inside the parentheses:

    public static void sayHelloInConsole() {
        System.out.println("Hello");
    }

Step 4: Run the koans again

Right-click EnglishPathToEnlightment.java and choose Run Java again:

Second result

The master expected Hello! and got Hello: the exclamation mark is missing. Fix it:

    public static void sayHelloInConsole() {
        System.out.println("Hello!");
    }

Run the koans once more:

Third result

The message changed because you passed. The master now reports your progress and shows the next koan.

You completed your first koan.

Part 3: Solve the rest

Repeat the same loop for every koan:

  1. Run EnglishPathToEnlightment.java.
  2. Read which koan failed and which file it is in.
  3. Read that koan's comment: goal, tips, and expected result.
  4. Write your code inside the koan's method.
  5. Run again. Fix what the master points out until the koan passes.

The master always stops at the first koan you have not solved, so you work through the series in the order below.

Rules

  • Write code only inside the method bodies, between { and }.
  • Do not rename methods. The master finds your answer by the method's name.
  • When a koan asks you to read input or pick a random number, use readLine() and random() as its tips describe. System.console() and Math.random() will not pass.
  • Do not edit the files in src/main/java/engine/ or src/main/java/sensei/. Grading replaces them with the original copies, so any change you make there is thrown away.

The series

# Series Covers File
1 console-and-variables Printing to and reading from the console, variables src/main/java/koans/english/AboutConsoleAndVariables.java
2 methods Methods src/main/java/koans/english/AboutMethods.java
3 conditions if, else src/main/java/koans/english/AboutConditions.java
4 more-methods More on methods src/main/java/koans/english/AboutMoreMethods.java
5 decimal-numbers double numbers src/main/java/koans/english/AboutDecimalNumbers.java
6 loops while loops src/main/java/koans/english/AboutLoops.java
7 not7-game The Not 7 game src/main/java/koans/english/AboutNot7Game.java
8 classes Packages and classes with static methods src/main/java/koans/english/AboutClasses.java
9 objects Objects, constructors, fields src/main/java/koans/english/AboutObjects.java

Bonus series

These two series are optional. They do not depend on the main series or on each other, so you can do them at any time. To run one, right-click the bonus file itself and choose Run Java.

Series Covers File
arrays Arrays and for loops src/main/java/bonuses/english/AboutArrays.java
interfaces Functional interfaces src/main/java/bonuses/english/AboutInterfaces.java

Part 4: Submit

Submit each series when you finish it.

  1. Commit your work. Use the Source Control panel, or run these in the terminal:

    git add -A
    git commit -m "Finish methods"
    
  2. In the terminal, run:

    ghsubmit
    
  3. Pick the series you are submitting from the numbered list. To skip the list, name the series directly, for example ghsubmit methods.

ghsubmit adds a small commit named "Submit " (for example "Submit methods"), pushes your work, and starts grading. Each submission makes its own commit, so you will see these commits in your history.

Only committed work is submitted. If you have uncommitted changes, ghsubmit warns you and asks whether to continue. Answer n, commit, and run ghsubmit again.

To fix something and try again, change your code, commit, and run the same ghsubmit command. You can resubmit as often as you like, even with no new changes.

Part 5: Check your results

Each submission creates a Release on your repo's Releases page on GitHub. ghsubmit prints the link when it finishes. The Release lists which koans passed and which failed. Results appear a few minutes after you submit.

Help

  • The Java Cheat Sheet summarizes the syntax you learn in the koans. Click JavaCheatSheet.pdf in the file list to open it in a tab beside your code.
  • If you are stuck on a koan, reread its tips and compare your console output with the expected result character by character. Then ask your mentor.

Credits and license

This course is a fork of FrcJavaKoans by jletroui, the original work, adapted to run as a Classroom 50 assignment.

Created by a mentor from the 3550 Robotronix team (Montréal, Canada).

Heavily inspired by the wonderful Ruby Koans.

The original dev container configuration, for GitHub Codespaces, was contributed by jmcconne10.

Typos have been fixed by someonesomething.

Many thanks to the early testers who gave feedback on the original course: Andy, Noémie, Chenxin, and Dumitru.

For the design behind the course, see the original repository.

CC BY-SA This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

About

Java Koans for the FRC is an interactive, step by step, course to teach Java to students engaged in the First Robotics Competition

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages