Lecture 10 (Sherriff) - Decisions Pt. 2

Lecture Date: Wednesday, February 4

More on if and else today.

Let’s start by looking again at the GradeCalculator.java.

Consider another way of figuring out the letter by looking at the individual digits of the grade:

mod operator
1
2
3
4
5
6
7
// Prompt the user

System.out.print("What's your grade? ");
int grade = keyboard.nextInt();

tens = grade / 10;
ones = grade % 10;

We can intentionally leverage integer division to get the tens place of the grade.

To get the ones place, we will use the modulus operator, which gives us the remainder after division.

We will spend time today touching on the following:

  • Scope (and scope errors)
  • switch statements
  • Reviews the logical operators: == ! != < > <= >= && ||
  • String.equals(), .charAt(), Comparing Strings
  • How to exit your program

Then, we’ll start on loops if we have time.

There are three types of loops that we will focus on today:

  • for
  • while
  • do while

Here’s how a for loop basically works:

for loop

Can we look through some text and replace certain words? Let’s try it!

Code from today: Decisions2.java