diff --git a/examples/stage0/snippets/src/JavaFundamentals.java b/examples/stage0/snippets/src/JavaFundamentals.java index 150edae5..ac936f06 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,10 +18,24 @@ 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] + // [stringConcatenation1] + double speed = 1; + System.out.println("Left Motor Speed " + speed); + //[/stringConcatenation1] + + // [stringConcatenation2] + int first = 6; + double second = 2.0; + + System.out.println(first + " " + second); + + //[/stringConcatenation2] + + // [singleLineComment] // This prints Hello World System.out.println("Hello World"); @@ -33,4 +50,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/examples/stage0/solutions/src/Print.java b/examples/stage0/solutions/src/Print.java index afb41697..550e8f0c 100644 --- a/examples/stage0/solutions/src/Print.java +++ b/examples/stage0/solutions/src/Print.java @@ -17,7 +17,7 @@ void main() { System.out.println("It knows this because it knows where it isn't."); // Define a variable `pi` that is equal to 3.14159. - // HINT: Make sure to pick the correct datatypes. + // HINT: Make sure to pick the correct data types. double pi = 3.14159; // Define an variable `g` that is equal to 10. int g = 10; @@ -25,13 +25,7 @@ void main() { String mode = "autonomous"; // Now, print all three variables in the **same** print statement, - // separated by spaces. You can do this by passing in the three variables, and - // "adding" an empty string (" ") in between each pair, as if you were adding - // two numbers together, using the `+` operator. Ex. [pi + " " + g]. - // Java recognizes that one of the items being added is a string, and - // converts the items on either side to a string before combining everything. - // This method of combining strings via the `+` operator is known as string - // concatenation. + // separated by spaces. System.out.println(pi + " " + g + " " + mode); // Now, change pi to equal 3.142857 (a slightly incorrect approximation of pi @@ -42,7 +36,7 @@ void main() { // Create a variable `degrees` of type `double` and assign it a value of // 360. Then, print the variable to observe type narrowing behavior // (it prints 360.0 with a decimal part, instead of just 360, since the - // variable uses a dataype with decimal parts). + // variable uses a data type with decimal parts). double degrees = 360; System.out.println(degrees); } \ No newline at end of file diff --git a/examples/stage0/templates/src/Print.java b/examples/stage0/templates/src/Print.java index d9c5cb2c..7d9eceb1 100644 --- a/examples/stage0/templates/src/Print.java +++ b/examples/stage0/templates/src/Print.java @@ -14,7 +14,7 @@ void main() { // Define a variable `pi` that is equal to 3.14159. - // HINT: Pick the correct datatypes. + // HINT: Pick the correct data types. // Define a variable `g` that is equal to 10. @@ -25,13 +25,7 @@ void main() { // Now, print all three variables in the **same** print statement, - // separated by spaces. You can do this by passing in the three variables, and - // "adding" an empty string (" ") in between both pairs, as if you were adding - // two numbers together, using the `+` operator. Ex. [pi + " " + g]. - // Java recognizes that one of the items being added is a string, and - // converts the items on either side to a string before combining everything. - // This method of combining strings via the `+` operator is known as string - // concatenation. + // separated by spaces. // Now, change pi to equal 3.142857 (a slightly incorrect approximation of pi @@ -41,6 +35,6 @@ void main() { // Create a variable `degrees` of type `double` and assign it a value of // 360. Then, print the variable to observe type narrowing behavior // (it prints 360.0 with a decimal part, instead of just 360, since the - // variable uses a dataype with decimal parts). + // variable uses a data type with decimal parts). } \ No newline at end of file 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 1229fda6..ae1bd886 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".