CS 145 Lecture 11 – Finalizing the big three
Agenda
- nesting
- printf
- Mr. Right
- leap
- exam
TODO
- Read sections 4.2 and 4.3.
Reverse Engineering
Code
MrRight.java
public class MrRight { public static boolean getTrue() { System.out.println("true"); return true; } public static boolean getFalse() { System.out.println("false"); return false; } public static void main(String[] args) { // boolean b = getTrue() && getFalse(); // boolean b = getFalse() && getTrue(); boolean b = getTrue() || getFalse(); } public static boolean isLeap(int year) { boolean isMultipleOf4 = year % 4 == 0; boolean isMultipleOf100 = year % 100 == 0; boolean isMultipleOf400 = year % 400 == 0; return isMultipleOf4 && (isMultipleOf400 || !isMultipleOf100); } public static boolean isMrRight(boolean isTall, boolean isDark, boolean isHandsome, boolean isRich) { return (isTall && isDark && isHandsome) || isRich; } }
Haiku
Sequence, loops, and if.
Elements. Like N, O, H.
Better wear goggles.
Elements. Like N, O, H.
Better wear goggles.