CS 145 Lecture 13 – Logic cont’d
Agenda
- what ?s
- compounding in Scratch
- not
- preventing bad input
- president material
Code
Logical.java
package lecture1001;
import java.util.Scanner;
public class Logical {
public static void main(String[] args) {
boolean isWrong = false;
boolean isRight = !isWrong;
// System.out.println(isRight);
Scanner in = new Scanner(System.in);
boolean hasBadData = !in.hasNextInt();
System.out.println(hasBadData);
// int luckyNumber = in.nextInt();
}
}
Potus.java
package lecture1001;
import java.util.Scanner;
public class Potus {
public static boolean isPresidentMaterial(int age,
String citizenship,
int nYearsResident,
int nTerms) {
return age >= 35 &&
nTerms < 2 &&
citizenship.equals("USA") &&
nYearsResident >= 14;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// String country = in.next(); // "USA"
System.out.println(isPresidentMaterial(75, in.next(), 76, 0));
}
}
Haiku
on overdoing it:
I do. Is
Love, let’s tie the and.
iDo && youDo
I do. Is
youDo
true too?Love, let’s tie the and.