add classes and methods lesson#117
Conversation
|
🌐 Preview URL: https://pr-117.frcsoftware.pages.dev |
6a9a47c to
6576c3c
Compare
| and other libraries, such as WPILib, | ||
| but you can also define your own object types. | ||
|
|
||
| Classes are a way to define object types. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
|
|
||
| } | ||
| ``` | ||
|
|
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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). |
There was a problem hiding this comment.
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: | ||
|
|
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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 | ||
| */ | ||
|
|
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
Description
I use two example classes here to demonstrate value classes and classes with mutable state.
Part of #16.
Meta
Merge checklist: