Unit 2 is about structures in programming: IF-ELSE, WHILE LOOPS, FOR LOOPS and RANDOM NUMBERS.
By the end of Unit 2 you should know
- how to write if and else statements
- how to write else-if (but only use when absolutely necessary)
- how to write nested if statements
- how to use logical operators: AND, OR, NOT
- how to use comparison operators: == != < <= > >=
- that strings should be compared using .equals() instead of ==
- that you should not check for booleans to be true or false because it leads to errors
if (gameOver == true) //never do this
- how to write while loops with conditions or with while(true)
- how to write do-while loops
- how to use break and continue in while/for loops
- how to use for loops (eg. to print something out 20 times)
- how to make for loops that start at a given number and increase by a certain amount
- when to use for loops and when to use while loops
- how to use Math.random() to set a certain percentage of something happening (e.g. a 30% chance that weather = "rain")
- how to make random numbers using both Math.random() and java.util.Random object
- make a random integer between 1 and some number
- switch statements
unit3: global and local variables, scope.
gr 12: ternary operator