09-21 Class Notes CS 107

09-21 Class Notes CS 107 - 10:15 AM CS 107 Fall 2011 Page 1...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
See the Programs page for links to solutions to program #2 In particular see the version using methods, aligning the output in columns 1. See the Piazza posting for comments on the Scratch programs 2. Midterm 2 is next week. How to study: - Take a couple of the old exams (available online through the Tests page) - Look at the format of a previous in-lab exam 3. Announcements: Questions? Methods: motivation, transfer of control, passing parameters Last Time: More about methods: return value, sharing values, overloading, scope Today: printf is for formatted printing. For instance: double value = 3.14159; // display using only 2 decimal places System.out.printf("%4.2f", value); Write code to swap the values in two int variables. [See code for swap.java developed during class] 09-21 Class Notes CS 107 Wednesday, September 21, 2011
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10:15 AM CS 107 Fall 2011 Page 1 a. Pass and catch same number & type of parameters b. When using a method call in place of a value, then that method must return a value that fits c. To share variables among methods, declare at the top of the class. These are called instance variables , a.k.a. class variables or fields for the class. [See code for swap.java developed during class] Mechanisms: "You can look out of a box, but not into a box" Think of the scope of methods, which is an issue when parameters in different parts of your program have the same name. [See other document under today's notes for Confuse.java] Scope How similar can two methods be? Can they have the same name? [See the program getNext.java developed in class] Overloading CS 107 Fall 2011 Page 2...
View Full Document

Page1 / 2

09-21 Class Notes CS 107 - 10:15 AM CS 107 Fall 2011 Page 1...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online