Lecture 24, CS 302-6, October 28

 

1. Reminders

            A. Program 2 – Due Friday night

                        i. EC – posted

                        ii.Extra office hours – Friday 1:15-4:30

            B. Program 1

                        i.  Scores posted – forms page of website

                        ii. Regrades – request by next Wednesday 5pm

2. Review

            A. ArrayLists

            1. Copying ArrayLists

                        2. ArrayLists of primitives via wrapper classes

                        3. ArrayLists as parameters and return values to methods

3. A couple of things about Program 2.

            A. Common issues:

                        0. How to use AntWorld-> you shouldn't need to touch it.  It's all handled for you.

                        1. Order of methods

                        2. Doubles vs ints (this is actually a problem with java)

                        double[] da = {1.1, 2.2, 3.3};

                        int sum = 0;

                        for (int i = 0; i < da.length; i++) {

                            sum += da[i];

                            //sum=sum+da[i];

                        }                                 

                        System.out.println(sum);                                  

                        3. Array indexes - always remember what your arrays represent, and what their columns and rows are.

                                    i. especially important to remember how this works if you are considering i+1, i-1 as indexes etc.

                                    ii. Note - you might have to get index values from other arrays for referencing array indexes - this works.

            4. Order of moving ants/moves (breadth first or depth first).

                        5. How often should you call updateTunnelAttractivenesses?

                                    i. In updateTunnelAttractivenesses, how often do you account for pheremone strength and evaporation?

                                    ii. Example - Hansel and Gretel, breadcrumbs...only have so many

                                    iii. Evaporation, on the other hand, is constant

                        6. > vs >=

            B. What to do when you're close, but not correct?

                        1. There are two types of errors - run time and compile time.  Some run time errors crash the program (array out of bounds, for instance).  Some don't - these are the hardest to debug

2. Question 1 - is there anywhere that I suspect I might have screwed up?                3. Focus on the tricky parts.

                        4. Debug (Eclipse)

                        5. Focus on the question - I know if I give it this I should get this out from this method.  Is it doing what it's supposed to?  If not, fix it.

                        6. How to avoid this situation in the first place - test a lot!  Each method, with easy data.  Verify the method works before they are all integrated together.  Methods as black boxes.

                        7. Why does it matter if you don't get the correct route?  Is close enough close enough?            No :)

4. Arrays of objects

             A. Examples - Strings, arrays

                         i. This is a good opportunity to talk about arrays of arrays

             B. Remember how arrays of objects are stored (diagram)

             C. We can use these objects stored in arrays as though they are normal objects

                         i. Generally:

                        Type[] name=new Type[size];

                        name[index]=new Type(args);

                        //...add more objects, update them

                        name[index].method(args);

             D. What to do with null?  Skip it!

             E. Example - ArrayOfStrings.java

5. HW – P2, read 7.1-7.4