lec10 - Lecture 10 Writing methods Parameters Returning...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Lecture 10 Writing methods Parameters Returning values from methods (Savitch 4.1) CS125 Course Notes Lecture 10, Slide 2 Recall from last day public class GameBoy { private double screenHeight = 4.5; private boolean isOn = false; private String currentGame; // other instance variables omitted public void turnGameOff() {} public void loadGame(String gameName) {} public boolean isGameOver() {} // other methods omitted } CS125 Course Notes Lecture 10, Slide 3 Invoking a method Void methods objectName . method ( arguments ); Examples: myGameBoy.loadGame("Pong"); (where myGameBoy is of type GameBoy and has been initialized) CS125 Course Notes Lecture 10, Slide 4 Invoking a method continued Methods that return values Variable = objectName . method ( arguments ); Examples: int numChars = myString.length(); boolean over = myGameBoy.isGameOver(); CS125 Course Notes Lecture 10, Slide 5 Writing a method Methods are part of a class Method_Signature { // Method body: // Java code to solve the problem // or answer the question....
View Full Document

This note was uploaded on 07/27/2009 for the course MATH 135 taught by Professor Andrewchilds during the Fall '08 term at Waterloo.

Page1 / 20

lec10 - Lecture 10 Writing methods Parameters Returning...

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

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