This lesson discusses printing a message in Java. Instead of extending Karel, students will now extend Console Program to print to the Console.
public class Welcome extends ConsoleProgram
{
public void run()
{
System.out.println("*insert message here* ");
System.out.println("*insert message here* ");
}
}
Students will be able to:
System.out.print
and System.out.println
Variables allow us to store information such as numbers, words, or true/false expressions. A variable can be thought of as a box that stores information inside. In Java, variables are composed of three things: a name, type, and value.
Students will able to write programs using variables by declaring, initializing and assigning a value to their variable.
In this lesson, students will learn how to retrieve user input by various methods including readLine, readInt, readDouble, and readBoolean. This will allow them to take in data from the user to make our programs work for them.
Students will be able to ask for user input and print out the input in the console program by using readLine, readInt, readDouble, and/or readBoolean.
Arithmetic Expressions allow us to perform mathematical operations within Java. Such expressions can be used for basic math and even more complex algorithms.
Students will able to
This lesson introduces the students to Casting, which is turning something of one type into another type.
Students will be able to…
How do we write code that tells us whether a user is logged in to our program? Booleans are the solution to these questions. A boolean refers to a value that is true or false. Those are the only values of a boolean expression, and these are useful if we want to check if something is true or false.
Students will be able to…
Logical operators allow us to connect or modify Boolean expressions. Three logical operators are the !, ||, && characters.
! = NOT
|| = OR
&& = AND
Logical operators can be used in combination.
With these logical operators, we can construct logical statements such as “I go to sleep when I am tired OR it’s after 9pm”, “I wear flip flops when I am outside AND it is NOT raining”
Students will be able to…
* Describe the meaning and usage of each logical operator: OR (||), AND (&&), and NOT (!)
* Construct logical statements using boolean variables and logical operators
Comparison operators let us compare two values. Using comparison operators in programming is similar to math in that less than <
, greater than >
, less than or equal to <=
, and greater than or equal to >=
are the same. The differences are that operators for equal to are ==
and not equal are !=
. Using comparison operators allows our program to make decisions.
Students will be able to…
* Explain the meaning of each of the comparison operators (<, <=, >, >=, ==, !=)
* Create programs using the comparison operators to compare values
* Predict the boolean result of comparing two values
* Print out the boolean result of comparing values
This lesson explores for loops–why they are useful, and how to use them to repeat code a fixed number of times.
Students will be able to…
* Create for loops to repeat code a fixed number of times
* Explain when a for loop would be a useful tool
* Utilize for loops to write programs that would be difficult / impossible without loops
Just like in Karel, Java has while loops. While loops are a way to repeat a block of code so long as some condition remains true. The condition is written in the form of a boolean expression. As long as the boolean expression remains true, code within the while loop will be executed. The moment that the boolean expression becomes false, code outside of the while loop will be executed; the loop is done.
Students will be able to…
This lesson introduces If Statements. We use if statements to run a segment of code only if some boolean expression first evaluates to true.
Students will be able to…
* Explain the purpose of if statements
* Create their own if statements to selective choose which code is executed in their programs
Infinite loops can occur unintentionally if you are not careful with the conditions of a while loop. In these cases, the infinite loop can cause the program to crash. However, infinite loops can be a very useful tool in programming. If your program needs to repeat a block of code an indefinite number of times, an infinite loop may be the correct approach. Repeating code is helpful, but it’s just as important to be able to stop the loop so that the rest of the program can continue executing. Loops can be stopped using the break statement. When the loop encounters a break statement, it quits running the loop and program flow continues.
Students will be able to…
This lesson introduces Short-Circuit Evaluations. In a Short-Circuit Evaluation, if the result of a Boolean Expression can be determined by the first argument, the second argument is not evaluated.
Students will be able to…
De Morgan’s Laws are rules that show how we can negate “and”s and “or”s. Not (A and B) is the same as (not A) or (not B). Similarly, not (A or B) is the same as (not A) and (not B).
Students will be able to…
A String is a sequence of characters. We use Strings to represent full words and sentences. For example, the famous “Hello World” is a String. Some more examples of Strings:
“I am a String. A sequence of characters strung together to form words and/or sentences.”
“CodeHS is the best coding website ever! Everyone loves CodeHS!”
“She sells sea shells by the sea shore.”
“Strings!”
“abcdefghijklmnopqrstuvwxyz”
A String is not a primitive type like int, char, boolean, and double are. Primitive types always start with lowercase letters, but a String starts with a capital letter. This makes it an object.
Students will be able to…
.equals
instead of ==
This lesson is a summative assessment of the unit’s learning objectives.
Assess student achievement of the learning goals of the unit