ISQA 360 – July 8, 2002 Methods Dr. Sergio Davalos.

Slides:



Advertisements
Similar presentations
Overloading Having more than one method with the same name is known as overloading. Overloading is legal in Java as long as each version takes different.
Advertisements

Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
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.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
Pass by Value. COMP104 Pass by Value / Slide 2 Passing Parameters by Value * A function returns a single result (assuming the function is not a void function)
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Introduction to C# Erick Pranata © Sekolah Tinggi Teknik Surabaya 1.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Introduction to Application Programming IST 256 Application Programming for Information Systems Xiaozhong Liu
Loops – While Loop Repetition Statements While Reading for this Lecture, L&L, 5.5.
Arrays Chapter 6 Chapter 6.
CS-341 Dick Steflik Introduction. C++ General purpose programming language A superset of C (except for minor details) provides new flexible ways for defining.
CS 117 Spring 2002 Review for Exam 2 March 6, 2002 open book, 1 page of notes.
CS241 PASCAL I - Control Structures1 PASCAL I - Control Structures Philip Fees CS241.
COMP More About Classes Yi Hong May 22, 2015.
1 4.3 Example: Volume of a Sphere Given the radius r, what is the weight of a ball (sphere) of wound twine?Given the radius r, what is the weight of a.
Sadegh Aliakbary Sharif University of Technology Spring 2011.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
Methods. 2 A sequence of statements can be packaged together as a unit and re-used. A method is a named unit of re-usable code. modifier returnType methodName(
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
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.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Static Methods. 2 Objectives Look at how to build static (class) methods Study use of methods calling, parameters, returning values Contrast reference.
Procedural programming in Java Methods, parameters and return values.
Chapter 5: Control Structures II
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Objects and Classes Mostafa Abdallah
Chapter 3 Introduction to Classes and Objects Definitions Examples.
CS241 PASCAL I - Control Structures1 PASCAL Control Structures Modified Slides of Philip Fees.
1 Controlling Behavior Chap.5 Study Sections 5.1 – 5.3 The if and for Statements.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
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.
C++ Programming Lecture 12 Functions – Part IV
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
CSCI 51 Introduction to Programming Dr. Joshua Stough February 24, 2009.
Chapter 9 Introduction to Arrays Fundamentals of Java.
Introduction to Programming G50PRO University of Nottingham Unit 6 : Control Flow Statements 2 Paul Tennent
Lesson 7 Iteration Structures. Iteration is the third control structure we will explore. Iteration simply means to do something repeatedly. All iteration.
Review – Primitive Data What is primitive data? What are 3 examples of primitive data types? How is a piece of primitive data different from an object?
Chapter 7 Control Structures. Java has very flexible three looping mechanisms. You can use one of the following three loops:  while Loop  do...while.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Recursion occurs when a method calls itself. public class RecursionOne { public void run(int x) { System.out.println(x); run(x+1); } public static void.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
CS100Lecture 61 Announcements Homework P1 due on Thursday Homework P2 handed out.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
Test 2 Review Outline.
Exam 2 Review.
Examples of Classes & Objects
University of Central Florida COP 3330 Object Oriented Programming
Starting Out with Java: From Control Structures through Objects
TO COMPLETE THE FOLLOWING:
Stack Memory 2 (also called Call Stack)
An Introduction to Java – Part I, language basics
Classes & Objects: Examples
Variables and Their scope
Review for Final Exam.
Unit 3 - The while Loop - Extending the Vic class - Examples
CS2011 Introduction to Programming I Methods (II)
BBIT 212/ CISY 111 Object Oriented Programming (OOP)
Review for Final Exam.
Scope of variables class scopeofvars {
Fundamental Programming
Corresponds with Chapter 5
Presentation transcript:

ISQA 360 – July 8, 2002 Methods Dr. Sergio Davalos

Methods What is a method Syntax Using methods Control Structures

What is a method Procedures Similarities between program segments Same code small changes Public static type name (parameters Class NameofClass extends Object No Static – instance Referencing – calling invoking – qualifier

Structure Heading Body Return Public static void main( )

Aspects of methods Local variable – example page 173 Calling argument – parameters, number and type Alias Copy of value

Show me Fig. 4.4 page 189 Class Sphere extends Object Public static double volume (double value1) Fig 4.5 import ann.easyio.*; Import Sphere; Class SphereWorld extends Object ( Public static void Snam (String [] args] )

Methods Control Structures Selection Repetion Selection if then else Public static double minmum(double first, double second) ( If (first < second) return first; Else return second; ) If else if else if - page 221

Repetition N! = 1 if n = 0, = 1X2X … n if n >0 Public static int fact( int n) ( Int product = 1: For (int count=2; count <= n; count ++) Product *= count; Return product; ) Page 228 – fig 5.4, 5.5

Other Forever loop For (;;) Termination condition If (boolean epression) break; Sentienl – flag Post-test Pre-test Fig 5.7 – example Instance method/ new instance