Skip to content
Open
Show file tree
Hide file tree
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
46 changes: 46 additions & 0 deletions examples/stage0/snippets/classes-methods/Point.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2026 FRCSoftware
*
* SPDX-License-Identifier: BSD-3-Clause
*/

// [pointFull]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting little comments that re-explain what section does can be helpful for new students

class Point {
// [finalFields]
private final double x;
private final double y;
// [/finalFields]
// [staticConstant]
public static final Point ORIGIN = new Point(0, 0);
// [/staticConstant]

// [constructor]
public Point(double x, double y) {
this.x = x;
this.y = y;
}
// [/constructor]

// [getters]
public double getX() { return this.x; }
public double getY() { return this.y; }
// [/getters]

// [plus]
public Point plus(Point other) {
return new Point(this.x + other.x, this.y + other.y);
}
// [/plus]

public Point minus(Point other) {
return new Point(this.x - other.x, this.y - other.y);
}

// [norm]
public double norm() {
double sumOfSquares = this.x * this.x + this.y * this.y;
return Math.sqrt(sumOfSquares);
}
// [/norm]
}
// [/pointFull]
42 changes: 42 additions & 0 deletions examples/stage0/snippets/classes-methods/RobotTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2026 FRCSoftware
*
* SPDX-License-Identifier: BSD-3-Clause
*/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting little comments that re-explain what section does can be helpful for new students

// [robotTrackerFull]
class RobotTracker {
// [mutableField]
private Point position;
// [/mutableField]

// [robotTrackerConstructor]
public RobotTracker(Point startPosition) {
this.position = startPosition;
}
// [/robotTrackerConstructor]

// [stateMutation]
public void move(Point delta) {
this.position = this.position.plus(delta);
}
// [/stateMutation]

// [localVariableChain]
public double distanceTo(Point target) {
Point diff = target.minus(this.position);
return diff.norm();
}
// [/localVariableChain]

public Point getPosition() {
return this.position;
}

// [useStaticConstant]
public void reset() {
this.position = Point.ORIGIN;
}
// [/useStaticConstant]
}
// [/robotTrackerFull]
31 changes: 31 additions & 0 deletions examples/stage0/snippets/classes-methods/Usage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2026 FRCSoftware
*
* SPDX-License-Identifier: BSD-3-Clause
*/

void main() {
// [createAndUse]
Point a = new Point(3, 4);
Point b = new Point(1, 2);

Point sum = a.plus(b);
System.out.println(sum.getX()); // 4.0
System.out.println(sum.getY()); // 6.0
System.out.println(a.norm()); // 5.0
System.out.println(a.equals(b)); // false
// [/createAndUse]

// [accessStaticConstant]
System.out.println(Point.ORIGIN.getX()); // 0.0
// [/accessStaticConstant]

// [trackerUsage]
RobotTracker tracker = new RobotTracker(Point.ORIGIN);
tracker.move(new Point(3, 0));
tracker.move(new Point(0, 4));
System.out.println(tracker.distanceTo(Point.ORIGIN)); // 5.0
tracker.reset();
System.out.println(tracker.getPosition().getX()); // 0.0
// [/trackerUsage]
}
8 changes: 4 additions & 4 deletions src/config/sidebarConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export const sidebarSections: Record<string, SidebarSection[]> = {
// label: 'Loops',
// slug: 'learning-course/stage0/loops',
// },
// {
// label: 'Objects',
// slug: 'learning-course/stage0/objects',
// },
{
label: 'Classes, Fields, and Methods',
slug: 'learning-course/stage0/classes-methods',
},
// {
// label: 'Methods',
// slug: 'learning-course/stage0/methods',
Expand Down
Loading
Loading