Please enable JavaScript to use CodeHS

Nevada Computer Science 2

Description

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* "); 
    } 
}
Objective

Students will be able to:

  • call system class methods to generate output to the console
  • recognize the difference between display behavior of System.out.print and System.out.println
  • create string literals
Description

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.

Objective

Students will able to write programs using variables by declaring, initializing and assigning a value to their variable.

Description

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.

Objective

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.

Description

Arithmetic Expressions allow us to perform mathematical operations within Java. Such expressions can be used for basic math and even more complex algorithms.

Objective

Students will able to

  • write programs with arithmetic expressions in their programs.
  • use increment and decrement shortcuts when writing their code.
Description

This lesson introduces the students to Casting, which is turning something of one type into another type.

Objective

Students will be able to…

  • Cast a variable of one type to another type
  • Explain the purpose of casting
  • Use casting to divide two ints and preserve the fractional part of the result
  • Use casting to round a double to the nearest int
Description

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.

Objective

Students will be able to…

  • Create boolean variables to represent meaningful yes/no values
  • Print out the value of a boolean variable
Description

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”

Objective

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

Description

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.

Objective

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

Description

This lesson explores for loops–why they are useful, and how to use them to repeat code a fixed number of times.

Objective

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

Description

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.

Objective

Students will be able to…

  • Explain the purpose of a while loop
  • Create while loops to repeat code while a condition is true
  • Utilize while loops to solve new types of problems
Description

This lesson introduces If Statements. We use if statements to run a segment of code only if some boolean expression first evaluates to true.

Objective

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

Description

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.

Objective

Students will be able to…

  • Explain the how the loop-and-a-half structure is different from a traditional while loop
  • Explain what an infinite loop is
  • Explain what the break statement does
  • Create programs that use the loop-and-a-half structure to repeat code until a SENTINEL is met, causing the program to break out of the loop
Description

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.

Objective

Students will be able to…

  • Explain what short circuit evaluation is
  • Explain why short circuit evaluation is useful
  • Identify situations where Java will use short circuit evaluation when running a program
  • Create programs that use short circuit evaluation to prevent crashing
Description

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).

Objective

Students will be able to…

  • Explain what De Morgan’s Laws are
  • Use De Morgan’s Laws to negate an OR statement
  • Use De Morgan’s Laws to negate an AND statement
Description

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.

Objective

Students will be able to…

  • Explain that a String is a sequence of characters
  • Explain the difference between a String and a primitive type
  • Create String variables and initialize them to hold String values
  • Concatenate String values together
  • Compare Strings correctly using .equals instead of ==
Description

This lesson is a summative assessment of the unit’s learning objectives.

Objective

Assess student achievement of the learning goals of the unit