Presentation is loading. Please wait.

Presentation is loading. Please wait.

[ ] Questions [ ] Lab / HW Notes [ ] try/catch blocks – keep control [ ] Notes - Documentation – what was changed - names – single characters –no sentenceAnalysis.

Similar presentations


Presentation on theme: "[ ] Questions [ ] Lab / HW Notes [ ] try/catch blocks – keep control [ ] Notes - Documentation – what was changed - names – single characters –no sentenceAnalysis."— Presentation transcript:

1 [ ] 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

2 [ ] 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

3 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

4 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?

5 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

6 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

7 for ( ; ; ) { } Pre-condition loop loop-controlled What is the ‘for-body’ Is the index automatically incremented? When? What goes in all the blank areas?

8 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

9 for ( int index = 0; index < 5; index++) { System.out.prinln(“hello!”); } Hand trace Output

10 Images --- METHOD

11 // Pre: type1, type2 // Post: retobty (type of returned object) public static retobty mName(type1 name1, type2 name2) { method body } Method signature mName: type1, type2

12 Images --- Scanner

13 Images --- Scanner

14 Images --- Scanner

15 - 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?


Download ppt "[ ] Questions [ ] Lab / HW Notes [ ] try/catch blocks – keep control [ ] Notes - Documentation – what was changed - names – single characters –no sentenceAnalysis."

Similar presentations


Ads by Google