Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.

Slides:



Advertisements
Similar presentations
AP Computer Science Anthony Keen. Computer 101 What happens when you turn a computer on? –BIOS tries to start a system loader –A system loader tries to.
Advertisements

1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
© 2007 Lawrenceville Press Slide 1 Chapter 5 The if Statement  Conditional control structure, also called a decision structure  Executes a set of statements.
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.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
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.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
1 Programming Languages and Paradigms Lisp Programming.
Introduction to Objects and Input/Output
CIS 234: Strings. What Is a String? series of characters enclosed in double quotes characters can include letters (lower case and upper case), digits,
Chapter 9 Characters and Strings. Topics Character primitives Character Wrapper class More String Methods String Comparison String Buffer String Tokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
COMP 14 Introduction to Programming Mr. Joshua Stough February 7, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
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,
StringBuffer class  Alternative to String class  Can be used wherever a string is used  More flexible than String  Has three constructors and more.
Fundamental Programming Structures in Java: Strings.
Strings, Etc. Part I: Strings. About Strings There is a special syntax for constructing strings: "Hello" Strings, unlike most other objects, have a defined.
COMPSCI 125 Spring 2005 ©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Odds and Ends Strings (from Chapter 9) StringTokenizer.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 9 Characters and Strings (sections ,
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.
JAVA LIBRARY CLASSES CITS Main concepts to be covered Using library classes: String, Math, Color Reading documentation Java 7 API is available.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Session 5 java.lang package Using array java.io package: StringTokenizer, ArrayList, Vector Using Generic.
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
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.
© 2005 Lawrenceville Press Slide 1 Chapter 5 Relational Operators Relational OperatorMeaning =greater than.
Functions Why we use functions C library functions Creating our own functions.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 4 part 3 GEORGE KOUTSOGIANNAKIS.
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.
Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.
The java.lang Package chapter 8 Java Certification Study Group February 2, 1998 Seth Ladd.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
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.)
Warm-Up: Monday, March 24 List as many commands in Java as you can remember (at least 10)
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.
Using Java Class Library
1 Textual Data Many computer applications manipulate textual data word processors web browsers online dictionaries.
Geoff Holmes Date Math Weighted Distr Strings String methods Tokenizers System Examples Utility Classes (Chapter 17) import java.util.*;
Jaeki Song JAVA Lecture 07 String. Jaeki Song JAVA Outline String class String comparisons String conversions StringBuffer class StringTokenizer class.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
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.
CHAPTER 8 File Input Output Part 1: String. The String Class  Constructing a String: String message = "Welcome to Java“; String message = new String("Welcome.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
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.
Declaring variables The type could be: int double char String name is anything you want like lowerCaseWord.
CIS Intro to JAVA Lecture Notes Set 5 26-May-05.
CSE 110: Programming Language I Afroza Sultana UB 1230.
Introduction to programming in java
Week 3 - Wednesday CS 121.
Agenda Warmup Lesson 1.4 (double precision, String methods, etc)
Strings, StringBuilder, and Character
Primitive Types Vs. Reference Types, Strings, Enumerations
Chapter 4 Conditionals.
Chapter 7: Strings and Characters
MSIS 655 Advanced Business Applications Programming
Advanced String handling
Functions October 23, 2017.
Chapter 5 Functional Methods.
Lecture 07 String Jaeki Song.
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
CS2011 Introduction to Programming I Strings
JavaScript: Objects.
Chapter 5 Functional Methods.
Presentation transcript:

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); double 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 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