teaching machines

CS 145 Lecture 13 – Logic cont’d

October 1, 2014 by . Filed under cs145, fall 2014, lectures.

Agenda

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:
iDo && youDo
I do. Is youDo true too?
Love, let’s tie the and.