[ ] Questions [ ] Lab / HW Notes [ ] try/catch blocks – keep control [ ] Notes - Documentation – what was changed - names – single characters –no sentenceAnalysis and all other methods - String is capitalized, double is not - method parameter list - method signature [ ] what is an object? Book, chair, freshman ap, student, classroom, biographical info
[ ] Lab / HW Notes - Loop endpoints are killers - Index out of range exception --- charAt(0) - In a for loop, DO NOT MUCK WITH THE INDEX - No single letter variable names (convention??) - total += count; what does this do? total = total + count; - Initialize all variables when declared - Study together – doing this class by yourself is really difficult - Ask questions
Java throws exceptions all over the place That’s good news – java is trying to help take care of us. So what tools can we use to maintain control? That’s really the issue – maintain control of your programs. If we try something and it works fine – great, no worry But if we try something and it blows up, we would like to be able to recover so we are not embarrassed
What could possibly go wrong? “Please enter an integer:” $ oh man!! What is the 4 th character of String S1 = “Hi!”; Well, it is S1.charAt(3) oh man!! The first is an InputMismatchException The second is an IndexOutOfBoundsException Why??? On both?
Help us out java: try { something if it works – great, continue on } catch (Exception somevariablename) { here’s our chance to avoid losing control – we catch the exception that java throws and handle it the way we want. } … java program continues
Examples see links on our web page tryCatch2.java tryCatch3.java tryCatch4.java Trouble in River City Trouble in River City – the reason for try/catch blocks
for ( ; ; ) { } Pre-condition loop loop-controlled What is the ‘for-body’ Is the index automatically incremented? When? What goes in all the blank areas?
for ( starting index ;logical expression; index mover) { for body index++ } The ‘index mover’ is implicit – automatically done on way up. Note: DO NOT MUCK WITH AN INDEX
for ( int index = 0; index < 5; index++) { System.out.prinln(“hello!”); } Hand trace Output
Images --- METHOD
// Pre: type1, type2 // Post: retobty (type of returned object) public static retobty mName(type1 name1, type2 name2) { method body } Method signature mName: type1, type2
Images --- Scanner
Images --- Scanner
Images --- Scanner
- Do not get paralyzed - Draw a picture - Write a story - What is the concept? - The helicopter perspective? Who’s in control – you or the CA?