Class 19-5

Class 19-5 - Methods in Java 1 Goals for Today n Build your...

Info iconThis preview shows pages 1–11. 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

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: Methods in Java 1 Goals for Today n Build your own Java methods n Define parameters and pass arguments to them n Build a method library 2 MGMT 290D Methods n How to perform a method Send a message to an object or class n Building a method in Alice Click the create new method button Drag statements into the method n Focus of Chapter 9 Learning how to build methods in Java 3 MGMT 290D Introductory Example: The Hokey Pokey Song n Problem: write a Java program to display song lyrics 4 MGMT 290D Introductory Example: The Hokey Pokey Song (continued) 5 Introductory Example: The Hokey Pokey Song (continued) n Brute force approach One String object stores the song lyrics One action displays those lyrics Implement program using one println() message Issue: program is about 60 lines long (excessive) 6 MGMT 290D Introductory Example: The Hokey Pokey Song (continued) n A better approach takes advantage of song structure Each verse only differs by the body part that is moved Implement program with a single method to print verse printVerse() takes one argument for the bodyPart 7 MGMT 290D Introductory Example: The Hokey Pokey Song (continued) 8 MGMT 290D Introductory Example: The Hokey Pokey Song (continued) 9 MGMT 290D Methods (continued) n Analyzing the first line of printVerse() public : allows another class access to the method static : indicates that the message is a class method void : indicates that the method does not return a value printVerse : the methods name () : contains parameters, such as String bodyPart { : indicates the beginning of the method statements...
View Full Document

Page1 / 27

Class 19-5 - Methods in Java 1 Goals for Today n Build your...

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

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