Chapter 5 Functional Methods.

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

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.
Midterm II ICS111. Two Classes used to read user input 1.Scanner 2.BufferedReader 3.StringReader 4.1 and and 3.
Chapter 7: The String class We’ll go through some of this quickly!
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
CSS, Programming Intro Week 4 INFM 603. Agenda JavaScript Intro.
Computers and Scientific Thinking David Reed, Creighton University Functions and Randomness 1.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Chapter 5 Functional Methods. © Daly and Wrigley Learning Java through Alice Objectives Properly construct and use methods when programming. Describe.
Lecture 2: Static Methods, if statements, homework uploader.
Copyright ©2005  Department of Computer & Information Science Using Number & Math Objects.
SE-1010 Dr. Mark L. Hornick 1 Some Java Classes using & calling methodsS.
GCOC – A.P. Computer Science A. College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose,
Java Program Components Java Keywords - Java has special keywords that have meaning in Java. - You have already seen a fair amount of keywords. Examples.
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions Image taken from:
Math class services (functions) Primitive vs reference data types Scanner class Math class services (functions) Primitive vs reference data types Scanner.
Chapter 7 Strings  Use the String class to process fixed strings.  Use the StringBuffer class to process flexible strings.  Use the StringTokenizer.
Java Software Solutions Lewis and Loftus Chapter 4 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Objects and Classes -- Introduction.
Math With Java The Math Class. First, A Quick Review of Math Operators in Java Primitive Data type in Java that represent numbers: Primitive Data type.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
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.
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.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 4 Methods Chapter.
Characters and Strings. Characters  New primitive char  char letter; letter = ‘a’; char letter2 = ‘C’;  Because computers can only represent numbers,
Lesson 6 Selection Structures. Example program //This will convert a numeric grade into a letter grade import TerminalIO.KeyboardReader; public class.
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.
CS 115 OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS Copyright: 2014 Illinois Institute of Technology- George Koutsogiannakis 1.
3 - 1 Text Processing In Java: Characters and Strings Reading:Downey: Chapter 7 Problem Set:Assignment #1 due Tuesday, Feburary 13 Wellesley College CS230.
Math Class Mrs. C. Furman September 2, Math frequently used methods NameUse floor()rounds down ceil()rounds up pow(x,y)returns x to the power of.
COMP 110 Static variables and methods Luv Kohli October 29, 2008 MWF 2-2:50 pm Sitterson 014.
A: A: double “4” A: “34” 4.
Computer Science 112 Fundamentals of Programming II.
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 9: Control Statements II CIS 275—Web Application Development for Business I.
COMPUTER PROGRAMMING I Objective 7.04 Apply Built-in Math Class Functions.
Conditional Control Structures Chapter 5 Review. The If Statement The if statement is a conditional control structure, also called a decision structure,
Lecture 5: java.lang.Math, java.lang.String and Characters Michael Hsu CSULA.
Chapter 4 Mathematical Functions, Characters, and Strings 1.
Chapter 4 Mathematical Functions, Characters, and Strings
Chapter 5 The if Statement
Chapter 4 Mathematical Functions, Characters, and Strings
Building Java Programs
Chapter 3 Methods.
Building Java Programs
Chapter 4 Conditionals.
CS 106A, Lecture 9 Problem-Solving with Strings
Building Java Programs
MSIS 655 Advanced Business Applications Programming
Chapter 4: Mathematical Functions, Characters, and Strings
The Math class The java.lang.Math class contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square.
Java's Math class Method name Description Math.abs(value)
Functions October 23, 2017.
Building Java Programs
Chapter 5 Methods.
METHODS, CLASSES, AND OBJECTS A FIRST LOOK
OBJECT ORIENTED PROGRAMMING I LECTURE 9 GEORGE KOUTSOGIANNAKIS
Relational Operators.
Using java libraries CGS3416 spring 2019.
Math class services (functions)
Objective 7.03 Apply Built-in Math Class Functions
Chapter 5 Functional Methods.
Ch 5 : Mathematical Functions, Characters, and Strings
Presentation transcript:

Chapter 5 Functional Methods

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.

JOptionPane

Math Class Method Description Method Call Result Argument Returns Returns the absolute value Math.abs(-5.5); 5.5 double Returns the value of the first argument raised to the power of the second argument Math.pow(5, 2); 25 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 none Returns the closest whole number to the argument Math.round(6.45); 6 Returns the rounded positive square root Math.sqrt(7); 2.6457513

String Methods Method Result String s1 = "Now is the winter of our discontent"; String s2 = "Java can be fun and hard "; Method Result 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

String Methods                       String s1 = "Now is the winter of our discontent"; String s2 = "Java can be fun and hard "; Method Result s1.endsWith(“TENT") false s2.endsWith("so") 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) s1.equalsIgnoreCase(s2) s1.contains("winter") true s2.contains("@")

Comparing Objects vs Primitives

String Comparisons

String Comparisons

String Tokenizer Need following import: 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. 

Alice Functional Methods

Method with Arguments & Return Value