Skip to content

add classes and methods lesson#117

Open
zachwaffle4 wants to merge 1 commit into
frcsoftware:mainfrom
zachwaffle4:stage0/classes-methods
Open

add classes and methods lesson#117
zachwaffle4 wants to merge 1 commit into
frcsoftware:mainfrom
zachwaffle4:stage0/classes-methods

Conversation

@zachwaffle4

Copy link
Copy Markdown
Member

Description

I use two example classes here to demonstrate value classes and classes with mutable state.

Part of #16.

Meta

Merge checklist:

@github-actions github-actions Bot added Curriculum material Curriculum materials, lessons for students, etc examples stage0 labels Jul 23, 2026
@github-actions

Copy link
Copy Markdown

🌐 Preview URL: https://pr-117.frcsoftware.pages.dev

@zachwaffle4
zachwaffle4 requested a review from Adrianamm July 23, 2026 01:36
@zachwaffle4 zachwaffle4 moved this to In progress in FRC Software Jul 23, 2026
@samfreund
samfreund force-pushed the stage0/classes-methods branch from 6a9a47c to 6576c3c Compare July 23, 2026 20:39
and other libraries, such as WPILib,
but you can also define your own object types.

Classes are a way to define object types.

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 this needs a non code example here to help students get a good understanding of what a class is. Especially since this page might be the first time students learn about classes. personally, big fan of using a dog to example what classes are. https://www.geeksforgeeks.org/java/classes-objects-java/
That can also be referenced in other sections and can help students understand everything better

## Defining Our Own Classes

Now that we know what a class is, let's define our own class.
Our first example will be a simple `Point` class that represents a point in a two-dimensional space.

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 explaining the point of a two dimensional space would be good here. Like out of all the examples, why that? Explaining that could be helpful


}
```

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 would explain the syntax here. Mainly what's public, and what's class. private is explained but public is not. I think explaining what public means can also help students understand the private explanation

}
```

Then, we're going to add three fields.

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 would explain what fields are

We also use the `private` keyword to make these fields **private**.
This means that they can only be accessed by methods in the same class.

Next, we're going to add a static constant field, ORIGIN, which represents the point at the origin (0, 0).

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 would explain what a static constant field is


`distanceTo` computes the straight-line distance from the current position to a target.
It uses a local variable `diff` to hold the vector between the two points before taking its length:

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.

minus is used but I think that has to be explained. Like where did it come from
also quickly mentioning where norm() came from may be helpful.

```

`reset` sets the position back to the origin.
Instead of writing `new Point(0, 0)`, we reuse the `Point.ORIGIN` constant:

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 would add why we reuse point.ORIGIN. To a new student, using new Point(0, 0) could seem like the same thing or better

*
* 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


The Java programming language has two types of types: **primitive types** and **reference types**.
**Primitive types** are the most basic types that are built into the language,
such as `int`, `double`, and `char`.

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.

could replace char or remove it since it's never mentioned before this page

**Object types** are more complex types that are defined by programmers.
Many object types come with the Java Development Kit (JDK), such as `String`,
and other libraries, such as WPILib,
but you can also define your own object types.

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.

Math is used often throughout this page and I left a comment or two about how we should explain what math is. I think using Math as an example could be helpful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Curriculum material Curriculum materials, lessons for students, etc examples stage0

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

2 participants