CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

23
CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann
  • date post

    20-Dec-2015
  • Category

    Documents

  • view

    218
  • download

    2

Transcript of CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Page 1: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

CS 206Introduction to Computer Science II

09 / 03 / 2008

Instructor: Michael Eckmann

Page 2: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Today’s Topics• Introduction of myself• Review the syllabus• List of Topics we'll cover• Testing & Debugging• Start Java Review (References, ...)• discussion of what we'll do in lab tomorrow

Page 3: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Reading homework

• Chapter 2 Reference Types

• Section 3.3 Javadoc

• First programming assignment to be assigned tomorrow.

Page 4: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Who is your instructor?• Most of you have had me for 106, but for those who I’ve not

had the pleasure of having as a student --- I'm Mike Eckmann and this is my fifth year at Skidmore. Before that I was at Lehigh University in PA.

• I studied Mathematics and Computer Engineering and Computer Science all at Lehigh University.

• I was employed as a programmer (systems analyst) for eight years.

Page 5: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Syllabus

• Office hours

• Text book

• Class room

• Assignments – Hw's &

programs

• Collaboration policy

• Grading schema

• Attendance

• Readings

http://www.skidmore.edu/~meckmann/2008Fall/cs206/index.html

The most up-to-date syllabus will be found on the course web page.

Page 6: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Suggestions on how to succeed in this (or any? CS) course

• Keep up on the reading before the class period that we cover it.

• Participate in class -- ask questions in class (best), via email or in my office.

• Start the programs as soon as they are assigned. You will run into snags. Debugging can take a long, long time.

• These are based on my observations of successful students in past classes.

Page 7: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• This semester our programs can be larger and more complex than in cs106. Therefore it's a good idea to think about how to test your programs for accuracy.

• Determining good test data to input to our programs is the first meaningful step in determining if our code is correctly written.

Page 8: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• Any ideas on what makes good test data?

• How have you tested your programs in the past?

Page 9: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• Choose test data for which you know the correct output.

• Pick test cases which are likely to cause errors.

• What kinds of things do you think often cause errors?

Page 10: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• Choose test data for which you know the correct output.

• Pick test cases which are likely to cause errors.

• What kinds of things do you think often cause errors?

– boundary values

• e.g. testing code that requires a month number (1

through 12) so we would try what numbers?

Page 11: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• Another necessary requirement of testing your code is to “fully exercise the code.”

– what do you think that means?

Page 12: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• If you find out that one or more of your tests yield incorrect results, then what?

Page 13: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• If you find out that one or more of your tests yield incorrect results, then what?

– Debug

• Maybe first read the code by eye and find out what is wrong.

• If that doesn't help, then could use a debugger that will allow you to run your program line by line or stop at certain places in your code and display values of variables, etc.

Page 14: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Testing & Debugging

• Once you find the bug, fix it, then you should run all the tests again to make sure your fix didn't cause problems for other input that did work before.

Page 15: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• A reference variable (aka reference) is a variable that

stores the memory address at which an object lives.

• References are variables of class types and arrays. Differentiate references from variable of the eight primitive types.

• null is the value a reference has when it does not refer to an object.

Page 16: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• Assignment operator =

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2 = new Card(6,1); // Six of Clubs

Card c3 = new Card(6,1); // Six of Clubs

c1 = c3; // assign reference c3 to c1

• When a reference is assigned to another reference what happens?

Page 17: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• Assignment operator =

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2 = new Card(6,1); // Six of Clubs

Card c3 = new Card(6,1); // Six of Clubs

c1 = c3; // assign reference c3 to c1

• When a reference is assigned to another reference what happens? Both references refer to the SAME object. That is, the memory address is copied. c1 and c3 are aliases for the same object.

Page 18: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• Equality comparison operator ==

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2 = new Card(6,1); // Six of Clubs

Card c3 = new Card(6,1); // Six of Clubs

if (c2 == c3)

System.out.println(“c2 and c3 are the same card”);

• When reference variables are compared for equality with ==, what happens?

Page 19: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• Equality comparison operator ==

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2 = new Card(6,1); // Six of Clubs

Card c3 = new Card(6,1); // Six of Clubs

if (c2 == c3) // if c2 and c3 are aliases

System.out.println(“c2 and c3 are the same card”);• When reference variables are compared for equality with ==, what

happens? If both references refer to the SAME object, then it evaluates to true. That is, if the memory addresses are the same, (if c2 and c3 are aliases for the same object) then true is evaluated.

• So will the above if condition be true?

Page 20: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• Not equal comparison operator !=

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2 = new Card(6,1); // Six of Clubs

Card c3 = new Card(6,1); // Six of Clubs

if (c2 != c3) // if c2 and c3 are not aliases

System.out.println(“c2 and c3 are not the same”);• When reference variables are compared with !=, what happens? If

both references refer to the SAME object, then it evaluates to false. That is, if the memory addresses are the same, (if c2 and c3 are aliases for the same object) then false is evaluated.

• So will the above if condition be false?

Page 21: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• What if we do the following:

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2;

System.out.println(“The card is “ + c1.toString());

System.out.println(“Another card is “ + c2.toString());

Page 22: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - References• What if we do the following:

• e.g.

Card c1 = new Card(5,0); // Five of Diamonds

Card c2;

System.out.println(“The card is “ + c1.toString());

System.out.println(“Another card is “ + c2.toString());

• Problem with c2.toString() because c2 DOES NOT refer to an object. Its value is null.

Page 23: CS 206 Introduction to Computer Science II 09 / 03 / 2008 Instructor: Michael Eckmann.

Michael Eckmann - Skidmore College - CS 206 - Fall 2008

Java review - ReferencesCard c1 = new Card(5,0); // Five of Diamonds

Card c2;

System.out.println(“The card is “ + c1.toString());

System.out.println(“Another card is “ + c2.toString());

• Either c2 needs to be assigned a non-null value from another reference

c2 = c1;

• Or it should be assigned to a newly instantiated object.

c2 = new Card(10, 3); // Ten of Spades