Creating and Using Class Methods. Definition Class Object.

Slides:



Advertisements
Similar presentations
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
Advertisements

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 MATH METHODS THAT RETURN VALUES. 2 JAVA'S MATH CLASS.
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
Methods Liang, Chapter 4. What is a method? A method is a way of running an ‘encapsulated’ series of commands. System.out.println(“ Whazzup ”); JOptionPane.showMessageDialog(null,
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
// Functions that take no arguments #include using namespace std; void function1(); void function2( void ); int main() { function1(); function2(); return.
Introduction to Computers and Programming Lecture 12: Math.random() Professor: Evan Korth New York University.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
Math class methods & User defined methods Math class methods Math.sqrt(4.0) Math.random() java.lang is the library/package that provides Math class methods.
Introduction to Java Programming, 4E Y. Daniel Liang.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Review for Midterm 2 Nested loops & Math class methods & User defined methods.
Chapter 4 Methods F Introducing Methods –Benefits of methods, Declaring Methods, and Calling Methods F Passing Parameters –Pass by Value F Overloading.
1 Chapter 5 Methods. 2 Introducing Methods A method is a collection of statements that are grouped together to perform an operation.
1 Topic 04 Methods Programming II/A CMC2522 / CIM2561 Bavy Li.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "methods" in Java Purpose Reuse code Modularize the program This.
METHODS Introduction to Systems Programming - COMP 1005, 1405 Instructor : Behnam Hajian
MATH AND RANDOM CLASSES.  The need for random numbers occurs frequently when writing software.  The Random class, which is part of the java.util class,
Class Example - Rationals Rational numbers are represented by the ratio of two integers, a numerator and a denominator, e.g., 2/3. This is opposed to irrational.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
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.
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.)
4-Methods Dr. John P. Abraham Professor UTPA. Common ways of packaging code Properties Methods Classes Namespaces (related classes are grouped into a.
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.
Lecture 5 Methods. Sometimes we want to perform the same sequence of operations multiple times in a program. While loops allow us to do this, they are.
Methods. Overview Class/Library/static vs. Message/non-static return and void Parameters and arguments.
Functions: Part 2 of /11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park 1.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Chapter 2: Functions and Models Lesson 7: Step Functions Mrs. Parziale.
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
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.
Review for Nested loops & Math class methods & User defined methods.
Let’s not leave anything to chance. How that process to generate random numbers takes places requires some complicated statistics that are outside the.
Methods Chapter 6. 2 Program Modules in Java What we call "functions" in C++ are called "___________________" in Java Purpose –Reuse code –Modularize.
Classes - Intermediate
ALGEBRA VOCABULARY. Vocabulary: Expression Definition: A math phrase built from constants, variables and operations EXAMPLE: 3X - 2Y.
CPSC 233 Tutorial 5 February 9 th /10 th, Java Classes Each Java class contains a set of instance variables and methods Instance Variables: Type.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Object-Oriented Programming Ramzi Saifan Program Control Slides adapted from Steven Roehrig.
Java Programming Static Methods.
Polymorphism in Methods
4. Java language basics: Function
Methods Chapter 6.
Functions, Part 2 of 2 Topics Functions That Return a Value
FIGURE 4-10 Function Return Statements
JavaScript Functions.
2008/11/10: Lecture 16 CMSC 104, Section 0101 John Y. Park
Method Mark and Lyubo.
Subroutines Idea: useful code can be saved and re-used, with different data values Example: Our function to find the largest element of an array might.
Working with Text and Numbers in Java
FIGURE 4-10 Function Return Statements
Class Inheritance (Cont.)
Defining Classes and Methods
Functions, Part 2 of 3 Topics Functions That Return a Value
Java Lesson 36 Mr. Kalmes.
CS2011 Introduction to Programming I Methods (I)
FIGURE 4-10 Function Return Statements
Chapter 5 Methods.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
Chapter 9: Value-Returning Functions
Predefined Functions Revisited
Classes, Objects and Methods
FIGURE 4-10 Function Return Statements
Random Numbers while loop
Functions, Part 2 of 3 Topics Functions That Return a Value
Functions, Part 2 of 3 Topics Functions That Return a Value
Presentation transcript:

Creating and Using Class Methods

Definition Class Object

Class Methods Math methods are an example Can be either void or return Can have parameters or not Must be static Should be public Know how to invoke (call) Be able to evaluate

Parameters Actual vs Formal Formal In the method definition Must have data types Actual In the method call Cannot have data types Must match the formal parameters in type, quantity and sequence

Void methods Can have parameters or not Have the keyword void in the heading

Return methods Can have parameters or not Do not have the keyword void in the heading Have a return statement in the body of the method

Math methods floor ceil round

Random values Use Math.random() Multiply times the range + 1 Add the small value To produce integer values, cast the result to be an integer Example, to produce a random value between 1 and 10: int x = (int)(Math.random() * );

String Methods length charAt indexOf equals