diff --git a/examples/stage0/snippets/src/JavaFundamentals.java b/examples/stage0/snippets/src/JavaFundamentals.java index 150edae5..8a3676ff 100644 --- a/examples/stage0/snippets/src/JavaFundamentals.java +++ b/examples/stage0/snippets/src/JavaFundamentals.java @@ -3,10 +3,13 @@ * * SPDX-License-Identifier: BSD-3-Clause */ +int matchTime = 0; + // [variables] -int CLIMBER_ID = 51; -double UP_POSITION = -33.5; -double DOWN_POSITION = 0; +int CLIMBER_ID = 51; // an integer named CLIMBER_ID that holds the value 51 +double UP_POSITION = 33.5; // a double named UP_POSITION that holds the value 33.5 +boolean isFinished = false; // a boolean named isFinished that holds the value false +String autoName = "Side Auto"; // a String named autoName that holds the value "Side Auto" // [/variables] void main() { @@ -15,8 +18,8 @@ void main() { // [/printLiteral] // [printVariable] - int number = 4; - System.out.println(number); // prints out the value 4 + int num = 4; + System.out.println(num); // prints out the value 4 // [/printVariable] // [singleLineComment] @@ -33,4 +36,14 @@ void main() { This is another line */ System.out.println("Hello World"); // [/multiLineComment] + + // [goodComment] + // Calculate how long is left in the match and show it to the drivers + System.out.println(150 - matchTime); + // [/goodComment] + + // [badComment] + // Print 150 minus matchTime + System.out.println(150 - matchTime); + // [/badComment] } diff --git a/examples/stage0/snippets/src/Operators.java b/examples/stage0/snippets/src/Operators.java index aecf4f1a..8ab2c813 100644 --- a/examples/stage0/snippets/src/Operators.java +++ b/examples/stage0/snippets/src/Operators.java @@ -10,11 +10,6 @@ // [/variables] void main() { - // [multiplication] - int magicNumber = 6; - System.out.println(magicNumber * 2); - // [/multiplication] - // [increments] int x = 6; int y = 7; @@ -50,4 +45,17 @@ void main() { System.out.println(fiveIsGreaterThanThree || nineIsLessThanTwo); System.out.println(!fiveIsGreaterThanThree); // [/logical] + + + // [math1] + int e = 0; + int f = 2; + System.out.println(e = f + 10); // prints 12 + // [/math1] + + // [math2] + int magicNumber = 6; + System.out.println(magicNumber * 2); // prints 12 + // [/math2] + } diff --git a/public/learning-course/stage0/conditionals/else.webp b/public/learning-course/stage0/conditionals/else.webp deleted file mode 100644 index 8927b166..00000000 Binary files a/public/learning-course/stage0/conditionals/else.webp and /dev/null differ diff --git a/public/learning-course/stage0/conditionals/elseif.webp b/public/learning-course/stage0/conditionals/elseif.webp deleted file mode 100644 index 4bfa4931..00000000 Binary files a/public/learning-course/stage0/conditionals/elseif.webp and /dev/null differ diff --git a/public/learning-course/stage0/conditionals/ifstatement.webp b/public/learning-course/stage0/conditionals/ifstatement.webp deleted file mode 100644 index 86cfa5cf..00000000 Binary files a/public/learning-course/stage0/conditionals/ifstatement.webp and /dev/null differ diff --git a/src/content/docs/learning-course/stage0/conditionals.mdx b/src/content/docs/learning-course/stage0/conditionals.mdx index 7d8d4c11..92dcd5a5 100644 --- a/src/content/docs/learning-course/stage0/conditionals.mdx +++ b/src/content/docs/learning-course/stage0/conditionals.mdx @@ -8,9 +8,9 @@ codeRegionSources: --- In everyday life, we make decisions based on different situations. -Such as "If we are hungry, then we get a snack" or "If we are tired, we go to bed". -Often in code, we want our program to do something similar and make different decisions based on different situations. -When programming a robot, one example could be "If the timer starts, drive the robot for 5 seconds then stop when the timer reached 15 seconds. +For example, "If we are hungry, then we get a snack" or "If we are tired, then we go to bed." +Robots often need to make different decisions depending on the situation. +For example, "If the timer starts, drive the robot for 5 seconds" or "If the timer is 0, stop driving." To add decisions to our code, we use conditionals. This section will cover three types of conditionals which are: @@ -26,14 +26,9 @@ This section will cover three types of conditionals which are: conditional.](https://www.w3schools.com/java/java_switch.asp) -Like we mentioned earlier in [Java Fundamentals](/learning-course/stage0/java-fundamentals/), all programming languages have syntax that needs to be followed. -One part of syntax is keywords. -As a reminder, a keyword is a reserved word that the compiler uses to run the code. -In Java, we use the following keywords for conditionals: `if`, `else if`, `else` - ## if -An `if` statement is a basic conditional. +An `if` statement runs code only if a specified condition is true. The syntax for an `if` statement is as follows: ```java #ifSyntax @@ -48,8 +43,7 @@ Let's break down what this means: - `{` an open curly braces is used to denote the opening of the conditional - `}` a closed curly braces is used to denote the end of the conditional -The code in between the opening and closing curly braces are called a "code block". -A code block a sequence of code that is enclosed in curly braces. +The code in between the opening and closing curly braces is called a "code block".