ISQA 360 – July 8, 2002 Methods Dr. Sergio Davalos
Methods What is a method Syntax Using methods Control Structures
What is a method Procedures Similarities between program segments Same code small changes Public static type name (parameters Class NameofClass extends Object No Static – instance Referencing – calling invoking – qualifier
Structure Heading Body Return Public static void main( )
Aspects of methods Local variable – example page 173 Calling argument – parameters, number and type Alias Copy of value
Show me Fig. 4.4 page 189 Class Sphere extends Object Public static double volume (double value1) Fig 4.5 import ann.easyio.*; Import Sphere; Class SphereWorld extends Object ( Public static void Snam (String [] args] )
Methods Control Structures Selection Repetion Selection if then else Public static double minmum(double first, double second) ( If (first < second) return first; Else return second; ) If else if else if - page 221
Repetition N! = 1 if n = 0, = 1X2X … n if n >0 Public static int fact( int n) ( Int product = 1: For (int count=2; count <= n; count ++) Product *= count; Return product; ) Page 228 – fig 5.4, 5.5
Other Forever loop For (;;) Termination condition If (boolean epression) break; Sentienl – flag Post-test Pre-test Fig 5.7 – example Instance method/ new instance