CS 145 Lecture 12 – Relational Operators

Agenda

  • what ?s
  • logic
  • logic in Scratch
  • relational operators

TODO

  • Read section 5.3. Share on a 1/4 sheet 2-3 questions, observations, or relational or logical expressions that you encounter in life.

Note

  1. someone is eligible for Social Security
  2. the batter can walk to first base
  3. someone is polygamous
  4. someone’s guessed the wrong number
  5. someone who’s been drinking can drive legally
  6. your love’s name is tattooable on your knuckles
  7. a string is blank
  8. a number of the format “(#)” is bigger than 100

Code

Relating.java

package lecture0930;

public class Relating {
  public static void main(String[] args) {
    System.out.println(isSocialSecurityEligible(72));
    System.out.println(isSocialSecurityEligible(40));
    System.out.println(isWalk(3));
    System.out.println(isWalk(4));
    System.out.println(isPolygamous(8));
    System.out.println(isPolygamous(0));
    System.out.println(isWrong(5, 6));
    System.out.println(isWrong(6, 6));
    System.out.println(isLegalToDrive(0.0799));
    System.out.println(isTattooable("Chris", 14));
    System.out.println(isTattooable("Demosthenes", 10));
  }

  public static boolean isSocialSecurityEligible(int age) {
    return age >= 62;
  }
  
  public static boolean isWalk(int nBalls) {
    return nBalls == 4;
  }
  
  public static boolean isPolygamous(int nSpouses) {
    return nSpouses > 1;
  }
  
  public static boolean isWrong(int guess, int answer) {
    return guess != answer;
  }
  
  public static boolean isLegalToDrive(double bac) {
    return bac < 0.08;
  }
  
  public static boolean isTattooable(String name, int nKnuckles) {
    return name.length() <= nKnuckles;
  }
}

Haiku

Happy birthday, Dad
I wish you’d reached a number
Greater than 60

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *