if
statement lets us change the flow of executionif (boolean expression) { //do something }
if (boolean expression) { //do something } else { // do something different }
Record your participation in Piazza clicker question Lesson9 Q1
In California a person can get a drivers license at 16 years of age. Which of the following is the best way to code that test?
a.if (age >= 16) System.out.println("Old enough to drive"); else if (age < 16) System.out.println("You will have to wait");b.
if (age >= 16) System.out.println("Old enough to drive"); else System.out.println("You will have to wait");c.
if (age >= 16) System.out.println("Old enough to drive"); if (age < 16) System.out.println("You will have to wait");
Record your participation in Piazza clicker question Lesson9 Q2
We want to modify the BankAccount deposit method so that the amount is added only if it is positive. Which is the best code to do that?
a.public void deposit(double amount) { if (amount > 0) { balance = balance + amount; } else { } }b.
public void deposit(double amount) { if (amount > 0) { balance = balance + amount; } }c.
public void deposit(double amount) { if (amount < 0) { } else { balance = balance + amount; } }
Record your participation in Piazza clicker question Lesson9 Q3
Which if statement will determine if age is 21?
int quantity1 = 20; int quantity2 = 20; quantity1 == quantity2 //true
String s1 = new String("ABC"); String s2 = new String("ABC"); s1 == s2 //false s1.equals(s2) //true String s3 = s1; s1 == s3 //true - but almost never useful
Record your participation in Piazza clicker question Lesson9 Q4
Write a program that asks the user for his/her favorite color. If the color is blue, print "Mine, too" Otherwise print "That's pretty, too". Ignore case so that blue, Blue, and BLUE are considered the same.
Here is the skeleton IO project from last time
Sometimes you want to do a whole series of things depending on some value. Use a structure line this
if(...) { //... } else if (...) { //... } else if (...) { //... } else { //... }
Record your participation in Piazza clicker question Lesson9 Q5
Java University does not use plus/minus grading. Any letter grade the user enters is translated to 0.0 through 4.0 or -1.0 if the grade is an error. The test is case insensitive
For example
In fact, anything starting with upper or lowercase B is translated to a 3.0.
Write a program that asks the user for a letter grade, then translates it to the appropriate grade point and prints it.
A or anything that starts with A or a -> 4.0
B or anything that starts with B or b -> 3.0
C or anything that starts with C or c -> 2.0
D or anything that starts with D or d -> 1.0
F or anything that starts with F or f -> 0.0
Anything else -> -1.0
Hint: You should get the first letter of the input using the substring method then convert the substring to uppercase and compare it to "A", "B", etc
Here is the skeleton IO project
Record your participation in Piazza clicker question Lesson9 Q6
In the previous activity, Test with these values. What do you get?