-
Notifications
You must be signed in to change notification settings - Fork 23
stage 0: add arrays + interfaces and lists lessons #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Adrianamm
merged 27 commits into
frcsoftware:main
from
zachwaffle4:stage0/interfaces-data-structures
Aug 30, 2026
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
07c418a
hi
Adrianamm 8905c69
I forgot a space
Adrianamm d665631
fixed maybe
Adrianamm ca704d9
added suggestions
Adrianamm 3afa8fb
added ignore
Adrianamm 564e650
Merge branch 'main' into fruitloops2
Adrianamm fbef351
Removed duplicate lockfile key, reverted package upgrades
httphypixelnet b6a7846
Merge pull request #1 from httphypixelnet/fruitloops2
Adrianamm 5fc09b3
fixed ignore
Adrianamm 537dec2
added ignore correctly
Adrianamm bcb43f1
Merge branch 'main' into fruitloops2
Adrianamm 2ba6756
Merge branch 'main' into fruitloops2
Adrianamm 8eae64c
Merge branch 'main' into fruitloops2
Adrianamm 5c19510
applied suggestions
Adrianamm 3c3002a
Merge branch 'main' into fruitloops2
Adrianamm efb7579
Merge branch 'main' into fruitloops2
zachwaffle4 45d0aee
fix pr
zachwaffle4 9471f82
fix loops snippets
zachwaffle4 10d199f
draft arrays page
zachwaffle4 bd94f4d
add interfaces and lists lesson
zachwaffle4 f8d173f
fix loops
zachwaffle4 b32cee7
Merge branch 'main' into stage0/interfaces-data-structures
Adrianamm df7b821
Merge branch 'main' into stage0/interfaces-data-structures
Adrianamm d82264b
review comments
zachwaffle4 cd73af1
Merge remote-tracking branch 'upstream/main' into stage0/interfaces-d…
zachwaffle4 1a6db9d
address review comments !!
zachwaffle4 bd516df
Merge remote-tracking branch 'upstream/main' into stage0/interfaces-d…
zachwaffle4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| void main() { | ||
| // [motorSpeedsLiteral] | ||
| double[] motorSpeeds = {0.5, 0.5, 0.5, 0.5}; | ||
| // [/motorSpeedsLiteral] | ||
|
|
||
| // [motorSpeedsEmpty] | ||
| double[] emptyMotorSpeeds = new double[4]; | ||
| // [/motorSpeedsEmpty] | ||
|
|
||
| // [setSpeed] | ||
| motorSpeeds[0] = 0.7; | ||
| System.out.println(motorSpeeds[0]); // 0.7 | ||
| // [/setSpeed] | ||
|
|
||
| // [speedsLength] | ||
| System.out.println(motorSpeeds.length); // 4 | ||
| // [/speedsLength] | ||
|
|
||
| // [pathArray] | ||
| Point[] path = { | ||
| new Point(0, 0), | ||
| new Point(1, 2), | ||
| new Point(3, 3), | ||
| }; | ||
| // [/pathArray] | ||
|
|
||
| // [pathArrayEmpty] | ||
| Point[] emptyPath = new Point[3]; | ||
| // [/pathArrayEmpty] | ||
|
|
||
| try { | ||
| // [pathArrayNull] | ||
| emptyPath[0].norm(); // error: emptyPath[0] is null | ||
| // [/pathArrayNull] | ||
| } catch (NullPointerException e) { | ||
| // for demo purposes we don't care about the exception' | ||
| } | ||
|
|
||
| // [indexLoopSpeeds] | ||
| double total = 0; | ||
| for (int i = 0; i < motorSpeeds.length; i++) { | ||
| total += motorSpeeds[i]; | ||
| } | ||
| System.out.println(total); // 2.2 | ||
| // [/indexLoopSpeeds] | ||
|
|
||
| // [forEachPath] | ||
| for (Point waypoint : path) { | ||
| System.out.println(waypoint.getX() + ", " + waypoint.getY()); | ||
| } | ||
| // [/forEachPath] | ||
|
|
||
| // [pathLength] | ||
| double pathLength = 0; | ||
| for (int i = 1; i < path.length; i++) { | ||
| Point segment = path[i].minus(path[i - 1]); | ||
| pathLength += segment.norm(); | ||
| } | ||
| System.out.println(pathLength); // 4.47213595499958 | ||
| // [/pathLength] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
examples/stage0/snippets/src/interfaces-lists/DistanceSensor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| // [distanceSensorInterface] | ||
| interface DistanceSensor { | ||
| double getDistanceMeters(); | ||
| } | ||
| // [/distanceSensorInterface] |
66 changes: 66 additions & 0 deletions
66
examples/stage0/snippets/src/interfaces-lists/InterfacesListsUsage.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| // [importList] | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| // [/importList] | ||
|
|
||
| // [isTooClose] | ||
| boolean isTooClose(DistanceSensor sensor) { | ||
| return sensor.getDistanceMeters() < 1.0; | ||
| } | ||
| // [/isTooClose] | ||
|
|
||
| // [genericLast] | ||
| <T> T last(T[] items) { | ||
| return items[items.length - 1]; | ||
| } | ||
| // [/genericLast] | ||
|
|
||
| void main() { | ||
| // [distanceSensorCall] | ||
| DistanceSensor ultrasonic = new UltrasonicSensor(); | ||
| DistanceSensor lidar = new LidarSensor(); | ||
| System.out.println(isTooClose(ultrasonic)); // false | ||
| System.out.println(isTooClose(lidar)); // false | ||
| // [/distanceSensorCall] | ||
|
|
||
| // [genericLastCall] | ||
| Point[] path = {new Point(0, 0), new Point(1, 2), new Point(3, 3)}; | ||
| DistanceSensor[] sensors = {ultrasonic, lidar}; | ||
|
|
||
| System.out.println(last(path).getX()); // 3.0 | ||
| System.out.println(last(sensors).getClass()); // class LidarSensor | ||
| // [/genericLastCall] | ||
|
|
||
| // [pairCall] | ||
| Pair<String, Integer> pair = new Pair<>("foo", 42); | ||
| String foo = pair.getFirst(); | ||
| Pair<Point, Point> pointPair = new Pair<>(new Point(0, 0), new Point(1, 2)); | ||
| Point secondPoint = pointPair.getSecond(); | ||
| // [/pairCall] | ||
|
|
||
| // [historyList] | ||
| List<Point> waypoints = new ArrayList<>(); | ||
| // [/historyList] | ||
|
|
||
| // [historyAdd] | ||
| waypoints.add(new Point(0, 0)); | ||
| waypoints.add(new Point(1, 2)); | ||
| System.out.println(waypoints.size()); // 2 | ||
| // [/historyAdd] | ||
|
|
||
| // [forEachHistory] | ||
| RobotHistoryTracker tracker = new RobotHistoryTracker(Point.ORIGIN); | ||
| tracker.move(new Point(3, 0)); | ||
| tracker.move(new Point(0, 4)); | ||
|
|
||
| for (Point visited : tracker.getHistory()) { | ||
| System.out.println(visited.getX() + ", " + visited.getY()); | ||
| } | ||
| // [/forEachHistory] | ||
| } |
15 changes: 15 additions & 0 deletions
15
examples/stage0/snippets/src/interfaces-lists/LidarSensor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| // [lidarSensorClass] | ||
| class LidarSensor implements DistanceSensor { | ||
| @Override | ||
| public double getDistanceMeters() { | ||
| // In real life, this would actually interact with hardware | ||
| return 1.2; | ||
| } | ||
| } | ||
| // [/lidarSensorClass] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
|
|
||
| // [pairClass] | ||
| public class Pair<A, B> { | ||
| private final A first; | ||
| private final B second; | ||
|
|
||
| Pair(A first, B second) { | ||
| this.first = first; | ||
| this.second = second; | ||
| } | ||
|
|
||
| public A getFirst() { | ||
| return first; | ||
| } | ||
|
|
||
| public B getSecond() { | ||
| return second; | ||
| } | ||
| } | ||
| // [/pairClass] |
33 changes: 33 additions & 0 deletions
33
examples/stage0/snippets/src/interfaces-lists/RobotHistoryTracker.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| // [robotHistoryTrackerClass] | ||
| class RobotHistoryTracker { | ||
| private Point position; | ||
| private final List<Point> history = new ArrayList<>(); | ||
|
|
||
| public RobotHistoryTracker(Point startPosition) { | ||
| this.position = startPosition; | ||
| this.history.add(startPosition); | ||
| } | ||
|
|
||
| public void move(Point delta) { | ||
| this.position = this.position.plus(delta); | ||
| this.history.add(this.position); | ||
| } | ||
|
|
||
| public Point getPosition() { | ||
| return this.position; | ||
| } | ||
|
|
||
| public List<Point> getHistory() { | ||
| return this.history; | ||
| } | ||
| } | ||
| // [/robotHistoryTrackerClass] | ||
15 changes: 15 additions & 0 deletions
15
examples/stage0/snippets/src/interfaces-lists/UltrasonicSensor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /* | ||
| * Copyright 2026 FRCSoftware | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| // [ultrasonicSensorClass] | ||
| class UltrasonicSensor implements DistanceSensor { | ||
| @Override | ||
| public double getDistanceMeters() { | ||
| // In real life, this would actually interact with hardware | ||
| return 1.5; | ||
| } | ||
| } | ||
| // [/ultrasonicSensorClass] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: I know that only
ArrayListis mentioned in the docs,LinkedListwould be better here. Could be an opportunity to mention there are multiple implementations ofListto support different use cases.LinkedListworks best here because we're only adding elements to the end, not inserting in the middle