Stage 0: Operators#20
Conversation
ArchdukeTim
left a comment
There was a problem hiding this comment.
There are already many free online courses that teach an introduction to java and its syntax. Would it be better to just recommend one of them as a precursor, rather than trying to reinvent the wheel?
| ``` | ||
| Data types refer to the type of value that our variable has. It helps tell our program more information about our variables such as what type of information it holds and how it can be used. | ||
| Data types can include numbers, characters or a string of words. Some examples of data types that are commonly used in FRC programming are: | ||
| * Int: integers or numbers that are positive or negative. Int only allows numbers without decimals. Example: 12 |
There was a problem hiding this comment.
| * Int: integers or numbers that are positive or negative. Int only allows numbers without decimals. Example: 12 | |
| * Int: integers, or whole numbers, that are positive or negative. Example: 12 |
| Data types refer to the type of value that our variable has. It helps tell our program more information about our variables such as what type of information it holds and how it can be used. | ||
| Data types can include numbers, characters or a string of words. Some examples of data types that are commonly used in FRC programming are: | ||
| * Int: integers or numbers that are positive or negative. Int only allows numbers without decimals. Example: 12 | ||
| * Double: Double: numbers that are positive or negative. Unlike int, double allows numbers with or without decimals. Example: 34.1 |
There was a problem hiding this comment.
| * Double: Double: numbers that are positive or negative. Unlike int, double allows numbers with or without decimals. Example: 34.1 | |
| * Double: numbers that are positive or negative. Unlike int, double allows numbers with or without decimals. Example: 34.1 |
| ## Syntax | ||
| As you start programming, you might make a mistake or make a typo. When that happens, your code will have a red line under it. This is because Java has rules called syntax. Syntax is a set of rules that have to be followed so that the computer can understand and run your code. It’s important to pay attention to the syntax! |
There was a problem hiding this comment.
Syntax errors are common, but not the only reason that you might get a compiler error. For example, using a misspelled variable name is valid syntax, but still an error.
| The name of your variable can be whatever you want. However, it should be easy to read and make sense to others who may be reading your code. | ||
| There are also some rules with variable names. The name of the variable can not include spaces. Instead you can write variables with camel case (frontLeftDrive) and snake case (front_Left_Drive). | ||
| Variable names can not start with a number. However, they can have a number at the end of the name. |
There was a problem hiding this comment.
can be whatever you want...rules with variable names
It would be better to just state what the rules and maybe conventions are
they can have a number at the end of the name
They can have a number anywhere except the start
| In FRC, variables can be used to hold information about the robot and its different mechanisms. The example below shows 3 variables that were used for a climber mechanism, CLIMBERID is an integer that holds the motor controller ID number which is 51. UP_POSITION is a double that holds the value -33.5 and DOWN_POSITION is a double that holds the value 0. | ||
| ```java | ||
| int CLIMBERID = 51; |
There was a problem hiding this comment.
| In FRC, variables can be used to hold information about the robot and its different mechanisms. The example below shows 3 variables that were used for a climber mechanism, CLIMBERID is an integer that holds the motor controller ID number which is 51. UP_POSITION is a double that holds the value -33.5 and DOWN_POSITION is a double that holds the value 0. | |
| ```java | |
| int CLIMBERID = 51; | |
| In FRC, variables can be used to hold information about the robot and its different mechanisms. The example below shows 3 variables that were used for a climber mechanism, CLIMBER_ID is an integer that holds the motor controller ID number which is 51. UP_POSITION is a double that holds the value -33.5 and DOWN_POSITION is a double that holds the value 0. | |
| ```java | |
| int CLIMBER_ID = 51; |
|
|
||
|
|
||
| ## Print statements | ||
| When programming, it can be useful to display information. This can be helpful for making programs that display information to the user or trying to see what speed that a motor is running. |
There was a problem hiding this comment.
| When programming, it can be useful to display information. This can be helpful for making programs that display information to the user or trying to see what speed that a motor is running. | |
| When programming, it can be useful to display information to the user. |
| When programming, it can be useful to display information. This can be helpful for making programs that display information to the user or trying to see what speed that a motor is running. | ||
| In Java, we can print information to a terminal using a print statement. A print statement in Java looks like: | ||
| ```java | ||
| System.out.print(“hello!”); |
There was a problem hiding this comment.
| System.out.print(“hello!”); | |
| System.out.println(“hello!”); |
| ```java | ||
| System.out.print(“hello!”); | ||
| ``` | ||
| What the print statement does is take information inside the parentheses, in the above example, it’s “hello!”, and prints it out to the terminal screen. When using a print statement, the text that we want to print out goes inside the parentheses and is in quotes. However, if we are printing out the value of a variable, then we do not need quotes, as shown below. |
There was a problem hiding this comment.
| What the print statement does is take information inside the parentheses, in the above example, it’s “hello!”, and prints it out to the terminal screen. When using a print statement, the text that we want to print out goes inside the parentheses and is in quotes. However, if we are printing out the value of a variable, then we do not need quotes, as shown below. | |
| Print statements print data to the console, a text-only message log. The console can be viewed on the driver station, or in VSCode |
- something about riolog at the end probably
| In Java, there are two types of comments. Single-line Comments and Multi-line Comments. | ||
|
|
||
| ### Single-line Comments | ||
| Single-line comments are // and you add them to the front of your text or line of code. For example, the code below leaves a note of “this prints out Hello World. |
There was a problem hiding this comment.
| Single-line comments are // and you add them to the front of your text or line of code. For example, the code below leaves a note of “this prints out Hello World. | |
| Single-line comments start with // . For example, the code below leaves a note of “this prints out Hello World. |
Added information about operators for stage 0
It includes: Arithmetic, Assignment, Comparison and Logical operators.
No exercise yet but I plan to add one in after all stage 0 material is written