SlideShare a Scribd company logo
Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods
Chapter Objectives ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Chapter Objectives (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Predefined Classes ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Predefined Classes (continued) Java Programming: From Problem Analysis to Program Design, 3e
Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
class  Character   (Package:  java.lang ) Java Programming: From Problem Analysis to Program Design, 3e
Java Programming: From Problem Analysis to Program Design, 3e class  Character   (Package:  java.lang ) (continued)
Java Programming: From Problem Analysis to Program Design, 3e class  Character   (Package:  java.lang ) (continued)
Syntax: Value-Returning Method Java Programming: From Problem Analysis to Program Design, 3e
User-Defined Methods ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Syntax ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Syntax (continued) ,[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e ,[object Object],[object Object],[object Object]
Equivalent Method Definitions Java Programming: From Problem Analysis to Program Design, 3e public static double  larger( double  x,  double  y) { double   max; if   (x >= y) max = x; else max = y; return   max; }
Equivalent Method Definitions (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Equivalent Method Definitions (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Programming Example: Palindrome Number ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Solution:  isPalindrome  Method Java Programming: From Problem Analysis to Program Design, 3e public static boolean  isPalindrome(String str) { int  len = str.length();  int  i, j; j = len - 1;  for  (i = 0; i <= (len - 1) / 2; i++) { if  (str.charAt(i) !=  str.charAt(j)) return false ; j--;  } return true ;  }
Sample Runs: Palindrome Number Java Programming: From Problem Analysis to Program Design, 3e
Sample Runs: Palindrome Number (continued) Java Programming: From Problem Analysis to Program Design, 3e
Flow of Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Programming Example: Largest Number ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Solution: Largest Number Java Programming: From Problem Analysis to Program Design, 3e static  Scanner console =  new  Scanner(System.in); public static void  main(String[] args) { double  num; double  max;  int  count; System.out.println(&quot;Enter 10 numbers.&quot;); num = console.nextDouble();  max = num;  for  (count = 1; count < 10; count++)  { num = console.nextDouble();  max = larger(max, num);  } System.out.println(&quot;The largest number is &quot; + max);  }
Sample Run: Largest Number Java Programming: From Problem Analysis to Program Design, 3e ,[object Object],[object Object],[object Object],[object Object]
Void Methods ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Void Methods: Syntax ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Void Methods with Parameters: Syntax Java Programming: From Problem Analysis to Program Design, 3e
Void Methods with Parameters: Syntax (continued) Java Programming: From Problem Analysis to Program Design, 3e
Primitive Data Type Variables as Parameters ,[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Reference Variables as Parameters   ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Uses of  Reference Variables as Parameters   ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Reference Variables as Parameters: type  String Java Programming: From Problem Analysis to Program Design, 3e
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e Example 7-11 public class  Example7_11 { public static void  main(String[] args) { int  num1;  //Line 1 IntClass num2 =  new  IntClass();  //Line 2 char ch;  //Line 3 StringBuffer str;  //Line 4 num1 = 10;  //Line 5 num2.setNum(15);  //Line 6 ch = 'A';  //Line 7 str = new StringBuffer(&quot;Sunny&quot;);  //Line 8 System.out.println(&quot;Line 9: Inside main: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot;    + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str);  //Line 9
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e funcOne(num1, num2, ch, str);  //Line 10 System.out.println(&quot;Line 11: After funcOne: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot;    + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str);  //Line 11 }
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e public static void  funcOne( int  a, IntClass b, char  v,    StringBuffer pStr) { int  num;  //Line 12 int  len;  //Line 13 num = b.getNum();  //Line 14 a++;  //Line 15 b.addToNum(12);  //Line 16 v = 'B';  //Line 17 len = pStr.length();  //Line 18 pStr.delete(0, len);  //Line 19 pStr.append(&quot;Warm&quot;);  //Line 20 System.out.println(&quot;Line 21: Inside funcOne: &quot; + &quot;  a = &quot; + a + &quot;, b = &quot; + b.getNum() + &quot;, v = &quot; + v + &quot;, pStr = &quot; + pStr + &quot;, len = &quot; + len + &quot;, and num = &quot; + num);  //Line 21 } }
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e num1 = 10;  //Line 5   num2.setNum(15);  //Line 6   ch = 'A';  //Line 7 str = new StringBuffer(&quot;Sunny&quot;);  //Line 8
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 9: Inside main: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot;  + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot;    + str);    //Line 9
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e int  num;  //Line 12   int  len;  //Line 13   num = b.getNum();  //Line 14
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e num = b.getNum();  //Line 14
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e a++;  //Line 15
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e b.addToNum(12);  //Line 16
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e v = 'B';  //Line 17
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e len = pStr.length();  //Line 18
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e pStr.delete(0, len);  //Line 19
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e pStr.append(&quot;Warm&quot;);  //Line 20
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 21: Inside funcOne: &quot; + &quot;  a = &quot; + a + &quot;, b = &quot; + b.getNum() + &quot;, v = &quot; + v + &quot;, pStr = &quot; + pStr + &quot;, len = &quot; + len + &quot;, and num = &quot; + num);  //Line 21
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e
Reference Variables as Parameters: type  String  (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 11: After funcOne: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot;  + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str);  //Line 11
Scope of an Identifier Within a Class ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Scope of an Identifier Within a Class (continued) ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Scope of an Identifier Within a Class (continued) ,[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Scope of an Identifier Within a Class (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Scope Rules ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Scope Rules (continued) ,[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Scope Rules (continued) Java Programming: From Problem Analysis to Program Design, 3e
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Scope Rules (continued) Java Programming: From Problem Analysis to Program Design, 3e
Scope Rules: Demonstrated Java Programming: From Problem Analysis to Program Design, 3e
Scope Rules: Demonstrated (continued) Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading:  An Introduction ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading (continued) ,[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Method Overloading (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Programming Example: Data Comparison ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Programming Example: Data Comparison (continued) Java Programming: From Problem Analysis to Program Design, 3e
Java Programming: From Problem Analysis to Program Design, 3e Programming Example: Data Comparison (continued)
Chapter Summary ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e
Chapter Summary (continued) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Java Programming: From Problem Analysis to Program Design, 3e

More Related Content

What's hot

Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
Radhika Talaviya
 
Ch1
Ch1Ch1
C programming session 08
C programming session 08C programming session 08
C programming session 08Dushmanta Nath
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
Richard Styner
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
lavparmar007
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
vikrammutneja1
 
Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab Scripts
Shameer Ahmed Koya
 
maXbox Starter 31 Closures
maXbox Starter 31 ClosuresmaXbox Starter 31 Closures
maXbox Starter 31 Closures
Max Kleiner
 
Looping
LoopingLooping
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
MuhammadBakri13
 
Methods In C-Sharp (C#)
Methods In C-Sharp (C#)Methods In C-Sharp (C#)
Methods In C-Sharp (C#)
Abid Kohistani
 
Python Objects
Python ObjectsPython Objects
Python Objects
MuhammadBakri13
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
Shameer Ahmed Koya
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
Prof. Dr. K. Adisesha
 
Generic programming
Generic programmingGeneric programming
Generic programming
Platonov Sergey
 

What's hot (20)

Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Ch06
Ch06Ch06
Ch06
 
Ch05
Ch05Ch05
Ch05
 
Ch13
Ch13Ch13
Ch13
 
Ch08
Ch08Ch08
Ch08
 
Ch1
Ch1Ch1
Ch1
 
C programming session 08
C programming session 08C programming session 08
C programming session 08
 
Ppt chapter11
Ppt chapter11Ppt chapter11
Ppt chapter11
 
Ch03
Ch03Ch03
Ch03
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to Matlab Scripts
Introduction to Matlab ScriptsIntroduction to Matlab Scripts
Introduction to Matlab Scripts
 
maXbox Starter 31 Closures
maXbox Starter 31 ClosuresmaXbox Starter 31 Closures
maXbox Starter 31 Closures
 
Looping
LoopingLooping
Looping
 
Conditional Statements
Conditional StatementsConditional Statements
Conditional Statements
 
Methods In C-Sharp (C#)
Methods In C-Sharp (C#)Methods In C-Sharp (C#)
Methods In C-Sharp (C#)
 
Python Objects
Python ObjectsPython Objects
Python Objects
 
Matlab Programming Tips Part 1
Matlab Programming Tips Part 1Matlab Programming Tips Part 1
Matlab Programming Tips Part 1
 
Introduction to c++ ppt
Introduction to c++ pptIntroduction to c++ ppt
Introduction to c++ ppt
 
Generic programming
Generic programmingGeneric programming
Generic programming
 

Viewers also liked

9781285852744 ppt ch17
9781285852744 ppt ch179781285852744 ppt ch17
9781285852744 ppt ch17
Terry Yoast
 
9781285852744 ppt ch01
9781285852744 ppt ch019781285852744 ppt ch01
9781285852744 ppt ch01
Terry Yoast
 
9781285852744 ppt ch18
9781285852744 ppt ch189781285852744 ppt ch18
9781285852744 ppt ch18
Terry Yoast
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
Terry Yoast
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
OXUS 20
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
yht4ever
 

Viewers also liked (8)

Chap08
Chap08Chap08
Chap08
 
Chap06
Chap06Chap06
Chap06
 
9781285852744 ppt ch17
9781285852744 ppt ch179781285852744 ppt ch17
9781285852744 ppt ch17
 
9781285852744 ppt ch01
9781285852744 ppt ch019781285852744 ppt ch01
9781285852744 ppt ch01
 
9781285852744 ppt ch18
9781285852744 ppt ch189781285852744 ppt ch18
9781285852744 ppt ch18
 
9781285852744 ppt ch02
9781285852744 ppt ch029781285852744 ppt ch02
9781285852744 ppt ch02
 
JAVA GUI PART I
JAVA GUI PART IJAVA GUI PART I
JAVA GUI PART I
 
GUI Programming In Java
GUI Programming In JavaGUI Programming In Java
GUI Programming In Java
 

Similar to Chap07

9781111530532 ppt ch07
9781111530532 ppt ch079781111530532 ppt ch07
9781111530532 ppt ch07Terry Yoast
 
9781111530532 ppt ch07
9781111530532 ppt ch079781111530532 ppt ch07
9781111530532 ppt ch07Terry Yoast
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07Terry Yoast
 
9781439035665 ppt ch03
9781439035665 ppt ch039781439035665 ppt ch03
9781439035665 ppt ch03Terry Yoast
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03Terry Yoast
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03Terry Yoast
 
9781439035665 ppt ch02
9781439035665 ppt ch029781439035665 ppt ch02
9781439035665 ppt ch02Terry Yoast
 
9781111530532 ppt ch02
9781111530532 ppt ch029781111530532 ppt ch02
9781111530532 ppt ch02Terry Yoast
 
9781111530532 ppt ch08
9781111530532 ppt ch089781111530532 ppt ch08
9781111530532 ppt ch08Terry Yoast
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
MLG College of Learning, Inc
 
Chapter 4 - Classes in Java
Chapter 4 - Classes in JavaChapter 4 - Classes in Java
Chapter 4 - Classes in Java
Khirulnizam Abd Rahman
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13Terry Yoast
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
Hock Leng PUAH
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
Hock Leng PUAH
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
Unviersity of balochistan quetta
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
vekariyakashyap
 

Similar to Chap07 (20)

Chap02
Chap02Chap02
Chap02
 
9781111530532 ppt ch07
9781111530532 ppt ch079781111530532 ppt ch07
9781111530532 ppt ch07
 
9781111530532 ppt ch07
9781111530532 ppt ch079781111530532 ppt ch07
9781111530532 ppt ch07
 
Chap14
Chap14Chap14
Chap14
 
9781439035665 ppt ch07
9781439035665 ppt ch079781439035665 ppt ch07
9781439035665 ppt ch07
 
9781439035665 ppt ch03
9781439035665 ppt ch039781439035665 ppt ch03
9781439035665 ppt ch03
 
Chap04
Chap04Chap04
Chap04
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03
 
9781111530532 ppt ch03
9781111530532 ppt ch039781111530532 ppt ch03
9781111530532 ppt ch03
 
9781439035665 ppt ch02
9781439035665 ppt ch029781439035665 ppt ch02
9781439035665 ppt ch02
 
9781111530532 ppt ch02
9781111530532 ppt ch029781111530532 ppt ch02
9781111530532 ppt ch02
 
9781111530532 ppt ch08
9781111530532 ppt ch089781111530532 ppt ch08
9781111530532 ppt ch08
 
Computer programming 2 Lesson 15
Computer programming 2  Lesson 15Computer programming 2  Lesson 15
Computer programming 2 Lesson 15
 
Chapter 4 - Classes in Java
Chapter 4 - Classes in JavaChapter 4 - Classes in Java
Chapter 4 - Classes in Java
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13
 
Getting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem SolvingGetting Started - Console Program and Problem Solving
Getting Started - Console Program and Problem Solving
 
SPF Getting Started - Console Program
SPF Getting Started - Console ProgramSPF Getting Started - Console Program
SPF Getting Started - Console Program
 
Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)Let's us c language (sabeel Bugti)
Let's us c language (sabeel Bugti)
 
Chap05
Chap05Chap05
Chap05
 
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
EContent_11_2023_04_09_11_30_38_Unit_3_Objects_and_Classespptx__2023_03_20_12...
 

More from Terry Yoast

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
Terry Yoast
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
Terry Yoast
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
Terry Yoast
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
Terry Yoast
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
Terry Yoast
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
Terry Yoast
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
Terry Yoast
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
Terry Yoast
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
Terry Yoast
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
Terry Yoast
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
Terry Yoast
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
Terry Yoast
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
Terry Yoast
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
Terry Yoast
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
Terry Yoast
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
Terry Yoast
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
Terry Yoast
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
Terry Yoast
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
Terry Yoast
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
Terry Yoast
 

More from Terry Yoast (20)

9781305078444 ppt ch12
9781305078444 ppt ch129781305078444 ppt ch12
9781305078444 ppt ch12
 
9781305078444 ppt ch11
9781305078444 ppt ch119781305078444 ppt ch11
9781305078444 ppt ch11
 
9781305078444 ppt ch10
9781305078444 ppt ch109781305078444 ppt ch10
9781305078444 ppt ch10
 
9781305078444 ppt ch09
9781305078444 ppt ch099781305078444 ppt ch09
9781305078444 ppt ch09
 
9781305078444 ppt ch08
9781305078444 ppt ch089781305078444 ppt ch08
9781305078444 ppt ch08
 
9781305078444 ppt ch07
9781305078444 ppt ch079781305078444 ppt ch07
9781305078444 ppt ch07
 
9781305078444 ppt ch06
9781305078444 ppt ch069781305078444 ppt ch06
9781305078444 ppt ch06
 
9781305078444 ppt ch05
9781305078444 ppt ch059781305078444 ppt ch05
9781305078444 ppt ch05
 
9781305078444 ppt ch04
9781305078444 ppt ch049781305078444 ppt ch04
9781305078444 ppt ch04
 
9781305078444 ppt ch03
9781305078444 ppt ch039781305078444 ppt ch03
9781305078444 ppt ch03
 
9781305078444 ppt ch02
9781305078444 ppt ch029781305078444 ppt ch02
9781305078444 ppt ch02
 
9781305078444 ppt ch01
9781305078444 ppt ch019781305078444 ppt ch01
9781305078444 ppt ch01
 
9781337102087 ppt ch13
9781337102087 ppt ch139781337102087 ppt ch13
9781337102087 ppt ch13
 
9781337102087 ppt ch18
9781337102087 ppt ch189781337102087 ppt ch18
9781337102087 ppt ch18
 
9781337102087 ppt ch17
9781337102087 ppt ch179781337102087 ppt ch17
9781337102087 ppt ch17
 
9781337102087 ppt ch16
9781337102087 ppt ch169781337102087 ppt ch16
9781337102087 ppt ch16
 
9781337102087 ppt ch15
9781337102087 ppt ch159781337102087 ppt ch15
9781337102087 ppt ch15
 
9781337102087 ppt ch14
9781337102087 ppt ch149781337102087 ppt ch14
9781337102087 ppt ch14
 
9781337102087 ppt ch12
9781337102087 ppt ch129781337102087 ppt ch12
9781337102087 ppt ch12
 
9781337102087 ppt ch11
9781337102087 ppt ch119781337102087 ppt ch11
9781337102087 ppt ch11
 

Recently uploaded

MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
SriSurya50
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
Priyankaranawat4
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
amberjdewit93
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
NelTorrente
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
amberjdewit93
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 

Recently uploaded (20)

MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptxFresher’s Quiz 2023 at GMC Nizamabad.pptx
Fresher’s Quiz 2023 at GMC Nizamabad.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
clinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdfclinical examination of hip joint (1).pdf
clinical examination of hip joint (1).pdf
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
MATATAG CURRICULUM: ASSESSING THE READINESS OF ELEM. PUBLIC SCHOOL TEACHERS I...
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 

Chap07

  • 1. Java Programming: From Problem Analysis to Program Design, 3e Chapter 7 User-Defined Methods
  • 2.
  • 3.
  • 4.
  • 5. Predefined Classes (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 6. Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
  • 7. Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
  • 8. Java Programming: From Problem Analysis to Program Design, 3e Predefined Classes (continued)
  • 9. class Character (Package: java.lang ) Java Programming: From Problem Analysis to Program Design, 3e
  • 10. Java Programming: From Problem Analysis to Program Design, 3e class Character (Package: java.lang ) (continued)
  • 11. Java Programming: From Problem Analysis to Program Design, 3e class Character (Package: java.lang ) (continued)
  • 12. Syntax: Value-Returning Method Java Programming: From Problem Analysis to Program Design, 3e
  • 13.
  • 14.
  • 15.
  • 16. Equivalent Method Definitions Java Programming: From Problem Analysis to Program Design, 3e public static double larger( double x, double y) { double max; if (x >= y) max = x; else max = y; return max; }
  • 17.
  • 18.
  • 19.
  • 20. Solution: isPalindrome Method Java Programming: From Problem Analysis to Program Design, 3e public static boolean isPalindrome(String str) { int len = str.length(); int i, j; j = len - 1; for (i = 0; i <= (len - 1) / 2; i++) { if (str.charAt(i) != str.charAt(j)) return false ; j--; } return true ; }
  • 21. Sample Runs: Palindrome Number Java Programming: From Problem Analysis to Program Design, 3e
  • 22. Sample Runs: Palindrome Number (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 23.
  • 24.
  • 25. Solution: Largest Number Java Programming: From Problem Analysis to Program Design, 3e static Scanner console = new Scanner(System.in); public static void main(String[] args) { double num; double max; int count; System.out.println(&quot;Enter 10 numbers.&quot;); num = console.nextDouble(); max = num; for (count = 1; count < 10; count++) { num = console.nextDouble(); max = larger(max, num); } System.out.println(&quot;The largest number is &quot; + max); }
  • 26.
  • 27.
  • 28.
  • 29. Void Methods with Parameters: Syntax Java Programming: From Problem Analysis to Program Design, 3e
  • 30. Void Methods with Parameters: Syntax (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 31.
  • 32.
  • 33.
  • 34. Reference Variables as Parameters: type String Java Programming: From Problem Analysis to Program Design, 3e
  • 35. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e Example 7-11 public class Example7_11 { public static void main(String[] args) { int num1; //Line 1 IntClass num2 = new IntClass(); //Line 2 char ch; //Line 3 StringBuffer str; //Line 4 num1 = 10; //Line 5 num2.setNum(15); //Line 6 ch = 'A'; //Line 7 str = new StringBuffer(&quot;Sunny&quot;); //Line 8 System.out.println(&quot;Line 9: Inside main: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot; + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str); //Line 9
  • 36. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e funcOne(num1, num2, ch, str); //Line 10 System.out.println(&quot;Line 11: After funcOne: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot; + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str); //Line 11 }
  • 37. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e public static void funcOne( int a, IntClass b, char v, StringBuffer pStr) { int num; //Line 12 int len; //Line 13 num = b.getNum(); //Line 14 a++; //Line 15 b.addToNum(12); //Line 16 v = 'B'; //Line 17 len = pStr.length(); //Line 18 pStr.delete(0, len); //Line 19 pStr.append(&quot;Warm&quot;); //Line 20 System.out.println(&quot;Line 21: Inside funcOne: &quot; + &quot; a = &quot; + a + &quot;, b = &quot; + b.getNum() + &quot;, v = &quot; + v + &quot;, pStr = &quot; + pStr + &quot;, len = &quot; + len + &quot;, and num = &quot; + num); //Line 21 } }
  • 38. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 39. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e num1 = 10; //Line 5 num2.setNum(15); //Line 6 ch = 'A'; //Line 7 str = new StringBuffer(&quot;Sunny&quot;); //Line 8
  • 40. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 9: Inside main: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot; + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str); //Line 9
  • 41. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e int num; //Line 12 int len; //Line 13 num = b.getNum(); //Line 14
  • 42. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e num = b.getNum(); //Line 14
  • 43. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e a++; //Line 15
  • 44. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e b.addToNum(12); //Line 16
  • 45. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e v = 'B'; //Line 17
  • 46. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e len = pStr.length(); //Line 18
  • 47. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e pStr.delete(0, len); //Line 19
  • 48. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e pStr.append(&quot;Warm&quot;); //Line 20
  • 49. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 21: Inside funcOne: &quot; + &quot; a = &quot; + a + &quot;, b = &quot; + b.getNum() + &quot;, v = &quot; + v + &quot;, pStr = &quot; + pStr + &quot;, len = &quot; + len + &quot;, and num = &quot; + num); //Line 21
  • 50. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 51. Reference Variables as Parameters: type String (continued) Java Programming: From Problem Analysis to Program Design, 3e System.out.println(&quot;Line 11: After funcOne: &quot; + &quot;num1 = &quot; + num1 + &quot;, num2 = &quot; + num2.getNum() + &quot;, ch = &quot; + ch + &quot;, and str = &quot; + str); //Line 11
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60. Scope Rules: Demonstrated Java Programming: From Problem Analysis to Program Design, 3e
  • 61. Scope Rules: Demonstrated (continued) Java Programming: From Problem Analysis to Program Design, 3e
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70. Java Programming: From Problem Analysis to Program Design, 3e Programming Example: Data Comparison (continued)
  • 71.
  • 72.