{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

Info icon This 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
Image of page 1

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

View Full Document Right Arrow Icon
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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern