Haidong Xue Summer 2011, at GSU Principles of Computer Programming (using Java) Chapter 8 More Control Structures Haidong Xue Summer 2011, at GSU
Content Quiz4 Assignment5 break and continue in if structure and loops switch structure exceptions
Quiz4 1:50pm – 2:00pm
Assignment5 Answers Should we output the result in DatabaseLogic.java? Why?
break and continue Always exit or go back to the nearest structure Example: BreakContinue.java
Labeled break and continue Exit or go back to the structure with the label Example: LabeledBreakContinue
switch structure switch ( expression ) { Integer (int, long ,short), char or enumeration expression switch ( expression ) { case constant-expression : statements … default : statements } The value can be determined by the compiler
switch structure What are the statements that are executed? The location of default Example: TestSwitch.java
Exceptions Type of exceptions: Throw a exception Checked exceptions (thrown by throw statements) Unchecked exceptions (embedded exceptions) Throw a exception throw exception_object;
Exceptions Handling exceptions Examples: TestExceptions.java try block catch (exception-type identifier) Examples: TestExceptions.java Improve previous codes
Assignment 6 Improve assignment 4, to solve the problem when the denominator is 0 Improve assignment 5, to solve the exceptions incurred by illegal inputs
Test 2 and Test 3 Test 2: Test 3: Using classes Structures: if, while, do-while, for, switch Using arrays Using methods (how parameters are passed) Exceptions Test 3: Everything
Grading policy [50, 100] <=> B-, B, B+, A-, A [0, 50] <=> F to C