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

Chapter 3 Objects, types, and values Bjarne Stroustrup
1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Lecture 15: I/O and Parsing
Computer Science 209 Software Development Equality and Comparisons.
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
Procedural programming in Java
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Introduction to Objects and Input/Output
©2004 Brooks/Cole Chapter 3 Interactive Input. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Standard Input and Output System.in Is Used to.
Chapter 7: The String class We’ll go through some of this quickly!
StringBuffer class  Alternative to String class  Can be used wherever a string is used  More flexible than String  Has three constructors and more.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Lecture 2: Static Methods, if statements, homework uploader.
CIS 260: App Dev I. 2 Objects and Reference Variables n Predefined Java classes you have used:  String —for defining and manipulating strings  Integer.
Chapter 8 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
CS 112 Department of Computer Science George Mason University CS 112 Department of Computer Science George Mason University Final Review Lecture 14.
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Chapter 9-Text File I/O. Overview n Text File I/O and Streams n Writing to a file. n Reading from a file. n Parsing and tokenizing. n Random Access n.
 2000 Prentice Hall, Inc. All rights reserved. 1 Chapter 2 - Introduction to Java Applications Outline 2.1Introduction 2.2A Simple Program: Printing a.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Characters. Character Data char data type – Represents one character – char literals indicated with ' '
Math Class Part of the Java.lang package. This package is from object so you do not have to import the lang package. Static: Math Class is static.
Characters, Strings, Reading Files CS2110, Week 2 Recitation.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
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.
Comp 248 Introduction to Programming Chapter 4 & 5 Defining Classes Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Strings and Text File I/O (and Exception Handling) Corresponds with Chapters 8 and 17.
Strings JavaMethods An Introduction to Object-Oriented Programming Maria Litvin Gary Litvin Copyright © 2003 by Maria Litvin, Gary Litvin, and Skylight.
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 2 Variables.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
Modularity Computer Science 3. What is Modularity? Computer systems are organized into components called modules. The extent to which this is done is.
Strings and Related Classes String and character processing Class java.lang.String Class java.lang.StringBuffer Class java.lang.Character Class java.util.StringTokenizer.
Chapter 10 Arrays. Learning Java through Alice © Daly and Wrigley Objectives Declare and use arrays in programs. Access array elements within an array.
Chapter 9 Control Structures.
Conditional Control Structures Chapter 5. Goals and Objectives Understand conditional control structures. Demonstrate the use of decision structures to.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
Chapter 6 Conditionals. Learning Java through Alice © Daly and Wrigley Objectives List relational operators. List logical operators. Use the hierarchy.
Chapter 5 Methods F Introducing Methods F Declaring Methods F Calling Methods F Passing Parameters F Pass by Value F Overloading Methods F Method Abstraction.
Java Methods and Applications CSIS 3701: Advanced Object Oriented Programming.
Strings, Characters and Regular Expressions
Methods Chapter 6.
Chapter 4 Mathematical Functions, Characters, and Strings
Chapter 3 Methods.
Primitive Types Vs. Reference Types, Strings, Enumerations
Chapter 4 Conditionals.
تعارف. تعارف قواعد العمل ا الموبيل المشروبات الاحاديث الجانبية الاسئلة نفكر.
MSIS 655 Advanced Business Applications Programming
Chapter 4: Mathematical Functions, Characters, and Strings
Functions October 23, 2017.
The compareTo interface
Chapter 5 Functional Methods.
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
JavaScript: Objects.
Using java libraries CGS3416 spring 2019.
Math class services (functions)
Chapter 5 Functional Methods.
Ch 5 : Mathematical Functions, Characters, and Strings
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 DescriptionMethod CallResultArgumentReturns 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 Comparing Objects vs Primitives 7

© Daly and Wrigley Learning Java through Alice String Comparisons 8

© Daly and Wrigley Learning Java through Alice String Comparisons 9

© 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. 10

© Daly and Wrigley Learning Java through Alice Alice Functional Methods 11

© Daly and Wrigley Learning Java through Alice Method with Arguments & Return Value 12