CS 145 Lecture 12 – Logic
Agenda
- what ?s
- blackbox
- logic in Scratch
- logical operators
TODO
- Quiz today. Be prepared to share a question in a pre-quiz review session.
- Finish homework 2. Schedule your trouble around office hours.
Blackbox
Code
Logical.java
package lecture0229;
public class Logical {
public static void main(String[] args) {
// boolean playedInParsnip = true;
// boolean playedInSunlight = true;
// boolean hasBlisters = playedInParsnip && playedInSunlight;
// System.out.println(hasBlisters);
boolean isTall = false;
boolean isDark = false;
boolean isHandsome = false;
boolean isRich = true;
boolean isMrRight = (isTall && isDark && isHandsome) || isRich;
System.out.println(isMrRight);
String filename = "family.JPEG".toLowerCase();
boolean isImage = filename.endsWith(".jpg") ||
filename.endsWith(".png") ||
filename.endsWith(".gif") ||
filename.endsWith(".tiff") ||
filename.endsWith(".bmp") ||
filename.endsWith(".webp");
System.out.println(isImage);
}
}
Haiku
on decision-making:
Yes, no, I don’t know
I rolled the third. Skip my turn?
Or act anyway?
Yes, no, I don’t know
I rolled the third. Skip my turn?
Or act anyway?