{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

14-methods - Mehran Sahami CS 106A Handout#14 October 8...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #14 CS 106A October 8, 2007 Methods Based on a handout by Eric Roberts Chapter 5 introduces the concept of methods in Java, which are analogous to those you created in Karel. In contrast to the topics of expressions and control statements, the material in Chapter 5 involves far fewer details. On the other hand, the ideas introduced in this chapter are far more important. If you plot overall importance on a scale of 1 to 10, the switch statement probably weighs in somewhere around 2 (and I'm being very generous here... poor old switch statement); methods are definitely a 10. The common idea that links methods in Karel and Java is that both provide a service to other, higher-level parts of the program and therefore act as tools. In both languages, the run method can call subsidiary methods to accomplish parts of the overall task. Those methods in turn call other methods that perform simpler operations, and so on. The caller views the method in terms of the effect it accomplishes. The method supplies all the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}