CS453 Intro and PA1 1CS453 Lecture Control Flow 1Teaching Reviews A chance to have a real impact on what happens in the university AFTER grades have been posted, anonymous reviews are read by– the professor (me)– the department chair– the tenure and promotion committees (not in a professor’s first year)– future students (not in a professor’s first year) What effect do they have?– Enables the professors to continually improve their teaching– Directly affects promotion and tenure– Affects how many students sign up for future courses taught by the same professor Detailed examples and/or suggestions about what works and what doesn’t have the most impactCS453 Lecture Control Flow 2Plan for Today Course Reviews IdExp: class references IdExp Control Flow– IfStatement– LTExp– NotExp– WhileStatement– AndExpCS453 Lecture Control Flow 3Class Reference Example class ClassRef { public static void main(String[] a){ System.out.println(new MyClass().testing()); } } class MyClass { int y; public int testing() { MyClass a; MyClass b; a = new MyClass(); b = new MyClass(); y = a.changeY(7); y = b.changeY(42); b = a; return b.getY() + a.getY() + y; } public int changeY(int p) { y = p; return 3; } public int getY() { return y;} }CS453 Lecture Control Flow 4IfStatement Example class IfStatement { public static void main(String[] a) { System.out.println(new Test().testing()); } } class Test { public int testing() { if (true) { System.out.println(1); } else { System.out.println(0); } if (false) { System.out.println(1); } else { System.out.println(0); } return 42; } }CS453 Intro and PA1 2CS453 Lecture Control Flow 5LTExp Example class LTExp { public static void main(String[] a) { System.out.println(new Test().testing()); } } class Test { public int testing() { if (3<4) { System.out.println(1); } else { System.out.println(0); } if (5<4) { System.out.println(1); } else { System.out.println(0); } return 42; } }CS453 Lecture Control Flow 6AndExp (short-circuiting) class And { public static void main(String[] a) { System.out.println(new Test().testing()); } class Test { int member; public int testing() { member = 1; if ( true && this.inc() ) { System.out.println(1); } else { System.out.println(0); } if ( false && this.inc() ) { System.out.println(1);} else { System.out.println(0); } System.out.println(member); return 42; } public boolean inc() { member = member + 1; return true; }
View Full Document