Method Mark and Lyubo.

Slides:



Advertisements
Similar presentations
Programming Methodology (1). Implementing Methods main.
Advertisements

CSCI 160 Midterm Review Rasanjalee DM.
PASSING PARAMETERS 1. 2 Parameter Passing (by Value) Parameters Formal Parameters – parameters listed in the header of the function Variables used within.
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
Constructors & An Introduction to Methods. Defining Constructor – Car Example Public class car { String Model; double speed; String colour; { Public Car.
Chapter 3, More on Classes & Methods Clark Savage Turner, J.D., Ph.D. Copyright 2003 CSTurner, from notes and text.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
COMP 14 Introduction to Programming Mr. Joshua Stough February 28, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Fundamental Programming Structures in Java: Strings.
COMP 110 Introduction to Programming Mr. Joshua Stough October 24, 2007.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
© 2007 Lawrenceville Press Slide 1 Chapter 7 Top-Down Development  Problem-solving approach  Breaking a task down into smaller subtasks  First level.
C Tokens Identifiers Keywords Constants Operators Special symbols.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Java Classes Methods Objects. Classes Classes We have been using classes ever since we started programming in Java Whenever we use the keyword class.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Chapter 4 Procedural Methods. Learning Java through Alice © Daly and Wrigley Objectives Identify classes, objects, and methods. Identify the difference.
Arrays Chapter 8. What if we need to store test scores for all students in our class. We could store each test score as a unique variable: int score1.
Chapter 2: Java Fundamentals
Copyright © 2012 Pearson Education, Inc. Chapter 6: Functions.
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.)
Functions Modules in C++ are called functions and classes Functions are block of code separated from main() which do a certain task every C++ program must.
Functions Top-down design Breaking a complex problem into smaller parts that we can understand is a common practice. The process of subdividing a problem.
CS346 Javascript -3 Module 3 JavaScript Variables.
When you read a sentence, your mind breaks it into tokens—individual words and punctuation marks that convey meaning. Compilers also perform tokenization.
VARIABLES Programmes work by manipulating data placed in memory. The data can be numbers, text, objects, pointers to other memory areas, and more besides.
1 Methods Introduction to Methods Passing Arguments to a Method More About Local Variables Returning a Value from a Method Problem Solving with Methods.
Functions in C CSE 2451 Rong Shi. Functions Why use functions? – Reusability Same operation, different data – Abstraction Only need to know how to call.
Java methods Methods break down large problems into smaller ones Your program may call the same method many times saves writing and maintaining same code.
Arithmetic, Class Variables and Class Methods Week 11
User Defined Methods Methods are used to divide complicated programs into manageable pieces. There are predefined methods (methods that are already provided.
Encapsulation, Inheritance, Composition. Class Methods Can be either void or return Can have parameters or not Must be static Should be public Know how.
Building java programs, chapter 3 Parameters, Methods and Objects.
Modularity using Functions Chapter 4. Modularity In programming blocks of code often can be "called up" and reused whenever necessary, for example code.
Aside: Running Supplied *.java Programs Just double clicking on a *.java file may not be too useful! 1.In Eclipse, create a project for this program or.
Creating and Using Class Methods. Definition Class Object.
Overloading a constructor If a constructor is overloaded, then an if statement in the client is needed when creating the object. We have always declared.
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
FUNCTIONS. Midterm questions (1-10) review 1. Every line in a C program should end with a semicolon. 2. In C language lowercase letters are significant.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Classes - Intermediate
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.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
Computer Programming II Lecture 4. Functions - In C++ we use modules to divide the program into smaller and manageable code. These modules are called.
SUMMARY OF CHAPTER 2: JAVA FUNDAMENTS STARTING OUT WITH JAVA: OBJECTS Parts of a Java Program.
Week 4 – Functions Coding Functions. Purpose of Coding Functions A function is written to perform a well-defined task; rather than having all logic in.
COMP 14 Introduction to Programming Mr. Joshua Stough March 23, 2005 Monday/Wednesday 11:00-12:15 Peabody Hall 218.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Suppose we want to print out the word MISSISSIPPI in big letters.
Suppose we want to print out the word MISSISSIPPI in big letters.
Chapter 7 Top-Down Development
Object Oriented Systems Lecture 03 Method
Chapter 4 Procedural Methods.
Programming Vocabulary.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
Name: Rubaisha Rajpoot
6 Chapter Functions.
Arrays We often want to organize objects or primitive data in a way that makes them easy to access and change. An array is simple but powerful way to.
Group Status Project Status.
Java Lesson 36 Mr. Kalmes.
Grouped Data Arrays, and Array Lists.
Workshop for Programming And Systems Management Teachers
Chapter 7 Procedural Methods.
IPC144 Introduction to Programming Using C Week 4 – Lesson 2
Method exercises Without IF
Lecture 03 & 04 Method and Arrays Jaeki Song.
Corresponds with Chapter 5
Presentation transcript:

Method Mark and Lyubo

Purpose to break down larger tasks into smaller ones to organize code

Declaring a method public static void drawBar (int length) { <return type> <parameters> <name> public static void drawBar (int length) { System.out.print("*"); } <access level> <statements>

Access level determines if the method can be called by other classes is either public or private Ex: public static void drawBar (int length)

Return type Declares if the method will return a value Ex: double, char, and int void will not return a value Ex: public static void drawBar (int length)

Name the name of the method starts with a lowercase and if there is more words the following words will be uppercase in no case do you add spaces public static void drawBar (int length)

Parameters values are used in a method parameters are enclosed by brackets parameters must be separated with commas Ex: public static void drawBar (int length)

Method declaration the keyword static in the method declaration makes the method able to be called from the class it is in Ex: public static void sumNum (int num1, int num2) { } If the return type is not void the return statement must be in the method

types of parameters types of parameters: formal and actual Ex: public void setText (String text) setText(“bob”); formal parameter actual parameter

Return Statement used when return type is other than void is specified in the method declaration return statement sends a value back to the method call can’t contain more than 1 value Ex: public static int areaOf(int size) { int area; area = size * size; return(area); }