We think you have liked this presentation. If you wish to download it, please recommend it to your friends in any social system. Share buttons are a little bit lower. Thank you!
Presentation is loading. Please wait.
Published byCarson McCarthy
Modified about 1 year ago
Chapter 5 Functional Methods
© Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe the difference between a procedural method and a functional method. Use the Java Application Interface to code programs. Place methods into a separate file and call them from the main program. 2
© Daly and Wrigley Learning Java through Alice JOptionPane 3
© Daly and Wrigley Learning Java through Alice Math Class Method Description Method Call Example ResultArgumentReturns Returns the absolute valueMath.abs(-5.5);5.5double Returns the value of the first argument raised to the power of the second argument Math.pow(5, 2);25 double, double double Returns a positive number that is greater than or equal to 0.0 and less than 1.0. Math.random( ); Number between 0 and 1 nonedouble Returns the closest whole number to the argument Math.round(6.45);6double Returns the rounded positive square root Math.sqrt(7);2.6457513double 4
© Daly and Wrigley Learning Java through Alice String Methods String s1 = "Now is the winter of our discontent"; String s2 = "Java can be fun and hard "; MethodResult s1.length( )35 s2.length( )25 s1.toUpperCase()NOW IS THE WINTER OF OUR DISCONTENT s2.toUpperCase()JAVA CAN BE FUN AND HARD s1.toLowerCase()now is the winter of our discontent s2.toLowerCase()java can be fun and hard s1.startsWith("st")False s2.startsWith("Java")true 5
© Daly and Wrigley Learning Java through Alice String Methods String s1 = "Now is the winter of our discontent"; String s2 = "Java can be fun and hard "; MethodResult s1.endsWith(“TENT")false s2.endsWith("so")false s1.replace( 'e','L' )Now is thL wintLr of our discontLnt s2.replace( 'a', '*' )J*v* c*n be fun *nd h*rd s1.equals(s2)false s1.equalsIgnoreCase(s2)false s1.contains("winter")true s2.contains("@")false 6
© Daly and Wrigley Learning Java through Alice String Tokenizer String s1 = "Now is the winter of our discontent"; StringTokenizer tokens = new StringTokenizer(s1); int x = tokens.countTokens(); Need following import: ▫ import java.util.StringTokenizer; Breaks up strings into pieces called tokens Tokens are separated by whitespace characters such as blanks, tabs, newlines, and carriage returns. 7
© Daly and Wrigley Learning Java through Alice Alice Functional Methods 8
© Daly and Wrigley Learning Java through Alice Method with Arguments & Return Value 9
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Objectives ► Become familiar with the class String ► ► Learn how to use input and output dialog boxes in a program ► ► Learn how to tokenize the input.
Fundamental Programming Structures in Java: Strings.
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement Conditional control structure, also called a decision structure Executes a set of statements.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
ROUND 1 Name a method associated with class String 1.) 15 compareTo() 26 indexOf() 34 length() 2.) 3.) 4.) 3 toUpper() 7 substring() 11 charAt() 5.)
Chapter 3 Introduction to Objects and Input/Output.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
CIS 234: Strings. What Is a String? series of characters enclosed in double quotes characters can include letters (lower case and upper case), digits,
USING JAVA CLASS LIBRARY Some other useful classes to use.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
Java Math Class. What is the Math Class? The Math Class is another class that is prepared by Java for us to use We use this class for mathematical operations.
1 CHAPTER 3 StringTokenizer. 2 StringTokenizer CLASS There are BufferedReader methods to read a line (i.e. a record) and a character, but not just a single.
CIS Intro to JAVA Lecture Notes Set 5 26-May-05.
Lecture 14 March 23, Exam Results Class Average was 69.4 –Median was 72.5 (which means there were some very low grades) Questions 31, 32, and 33.
Functions and methods A method is a function that is a member of a class FCL(Framework Class Library) provides a rich collection of classes and methods.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
StringBuffer class Alternative to String class Can be used wherever a string is used More flexible than String Has three constructors and more.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
Chapter 3A Strings. Using Predefined Classes & Methods in a Program To use a method you must know: 1.Name of class containing method (Math) 2.Name of.
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
11 Chapter 5 METHODS CONT’D. 22 MORE ON PASSING ARGUMENTS TO A METHOD Passing an Object Reference as an Argument to a Method Objects are passed by reference.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
Strings Chapter 7. An object of the String class represents a string of characters. The String class belongs to the java.lang package, which does.
COMP 14 Introduction to Programming Miguel A. Otaduy May 17, 2004.
CSE 110: Programming Language I Afroza Sultana UB 1230.
23-Jun-15 Strings, Etc. Part I: String s. 2 About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects,
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
COMP 14 Introduction to Programming Mr. Joshua Stough February 7, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
1 Programming Languages and Paradigms Lisp Programming.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
Functions Why we use functions C library functions Creating our own functions.
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning greater than >=greater than.
CHAPTER 8 File Input Output Part 1: String. The String Class Constructing a String: String message = "Welcome to Java“; String message = new String("Welcome.
© 2017 SlidePlayer.com Inc. All rights reserved.