Computer Programming 2 Lecture 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION.

Slides:



Advertisements
Similar presentations
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Advertisements

(C) 2010 Pearson Education, Inc. All rights reserved. Java™ How to Program, 8/e.
A Java API Package java.security  The Java Security Package contains classes and interfaces that are required by many Java programs.  This package is.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
Run-Time Storage Organization
Review for Midterm 2 Nested loops & Math class methods & User defined methods.
Chapter 7 Methods: A Deeper Look Visual C# 2010 How to Program © by Pearson Education, Inc. All Rights Reserved.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 16: Working with Text.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 6 Introduction to classes and objects.
Advanced Programming Collage of Information Technology University of Palestine, Gaza Prepared by: Mahmoud Rafeek Alfarra Lecture 1: Course overview.
Dale Roberts Procedural Programming using Java Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Data Modeling Using the Entity- Relationship (ER) Model Hour1 Presented.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
4 th Week Spring 2011 Methods 1. Outline Introduction Why method ? Static methods vs. non-static methods Example: Math class Declare a method Signature.
* * 0 Chapter 6 Java Methods. * * 0 Method Syntax [access specifier][qualifier] return type method name(argument list) Access specifier public – method.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 1: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER.
 2005 Pearson Education, Inc. All rights reserved. 1 Methods Called functions or procedures in other languages Modularize programs by separating its tasks.
 2005 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Android How to Program, 2/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Part II © Copyright by Pearson Education, Inc. All Rights Reserved.
4-Methods Dr. John P. Abraham Professor UTPA. Common ways of packaging code Properties Methods Classes Namespaces (related classes are grouped into a.
Introduction To Programming Information Technology , 1’st Semester
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 6.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Introduction to C Programming Lecture 6. Functions – Call by value – Call by reference Arrays Today's Lecture Includes.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 15,16 Java’s Methods.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 10: File streaming (1) Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &
Review for Nested loops & Math class methods & User defined methods.
Computer Programming 2 Lecture 8: Object Oriented Programming Creating Classes & Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Function Call Stack and Activation Frame Stack Just like a pile of dishes Support Two operations push() pop() LIFO (Last-In, First-Out) data structure.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
(C) 2010 Pearson Education, Inc. All rights reserved.  Best way to develop and maintain a large program is to construct it from small, simple pieces,
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Mark Fontenot CSE Honors Principles of Computer Science I Note Set 6.
Presented By: Mahmoud Rafeek Alfarra
Presented By: Mahmoud Rafeek Alfarra
Programming Fundamentals Lecture #7 Functions
Chapter 6 Methods: A Deeper Look
Introduction To Programming Information Technology , 1’st Semester
Part a: Fundamentals & Class String
MSIS 655 Advanced Business Applications Programming
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
CSCI 3328 Object Oriented Programming in C# Chapter 6: Methods
6 Methods: A Deeper Look.
Presented By: Mahmoud Rafeek Alfarra
Introduction To Programming Information Technology , 1’st Semester
Presented By: Mahmoud Rafeek Alfarra
Presentation transcript:

Computer Programming 2 Lecture 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE

و من يتقِ الله... كلمة التقـوى : وَأَلْزَمَهُمْ كَلِمَةَ التَّقْوَى ( إِذْ جَعَلَ الَّذِينَ كَفَرُوا فِي قُلُوبِهِمُ الْحَمِيَّةَ حَمِيَّةَ الْجَاهِلِيَّةِ فَأَنْزَلَ اللَّهُ سَكِينَتَهُ عَلَى رَسُولِهِ وَعَلَى الْمُؤْمِنِينَ وَأَلْزَمَهُمْ كَلِمَةَ التَّقْوَى وَكَانُوا أَحَقَّ بِهَا وَأَهْلَهَا وَكَانَ اللَّهُ بِكُلِّ شَيْءٍ عَلِيماً ) ( الفتح :26) Mahmoud Rafeek Alfarra 2 Downloaded from شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي

Out Lines Mahmoud Rafeek Alfarra Downloaded from Downloaded from 3 Notes on Declaring and Using Methods Method Call Stack and Activation Records Case Study: Random-Number Generation Case Study: A Game of Chance Method Overloading General Practices about Methods

Notes on Declaring and Using Methods Mahmoud Rafeek Alfarra Downloaded from Downloaded from 4 There are three ways to call a method: 1. Using a method name by itself to call another method of the same class such as maximum( number1, number2, number3 ) 2. Using a variable that contains a reference to an object, followed by a dot (.) and the method name to call a method of the referenced object. maximumFinder.determineMaximum() 3. Using the class name and a dot (.) to call a static method of a classsuch as Math.sqrt( )

Method Call Stack and Activation Records Mahmoud Rafeek Alfarra Downloaded from Downloaded from 5 When a program calls a method, the called method must know how to return to its caller, so the return address of the calling method is pushed onto the program execution stack (sometimes referred to as the method call stack). If a series of method calls occurs, the successive return addresses are pushed onto the stack in last-in, first-out order so that each method can return to its caller.

Method Call Stack and Activation Records Mahmoud Rafeek Alfarra Downloaded from Downloaded from 6 The program execution stack also contains the memory for the local variables used in each invocation of a method during a program's execution. This data, stored as a portion of the program execution stack, is known as the activation record or stack frame of the method call.

Case Study: Random-Number Generation Mahmoud Rafeek Alfarra Downloaded from Downloaded from 7 The element of chance can be introduced in a program via an object of class Random (package java.util) or via the static method random of class Math. Objects of class Random can produce random boolean, byte, float, double, int, long and Gaussian values, whereas Math method random can produce only double values.

Case Study: Random-Number Generation Mahmoud Rafeek Alfarra Downloaded from Downloaded from 8 A new random-number generator object can be created as follows: Random new Random Random randomNumbers = new Random(); Then, to generate a random int values: int randomValue = randomNumbers.nextInt(); int randomValue = randomNumbers.nextInt( 2 ); int randomValue = randomNumbers.nextInt( 10 );

Case Study: A Game of Chance Mahmoud Rafeek Alfarra Downloaded from Downloaded from 9 Write a program to simulate any game which depends on generating random values, you can read the section 6.10 to more information. ‏ عَنْ ‏‏ أَبِي مُوسَى الْأَشْعَرِيِّ ‏‏ أَنَّ رَسُولَ اللَّهِ ‏‏ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ ‏‏ قَالَ ‏ " ‏ مَنْ لَعِبَ ‏ ‏ بِالنَّرْدِ ، ‏ ‏ فَقَدْ عَصَى اللَّهَ وَرَسُولَهُ ” صحيح

In the next Lecture Mahmoud Rafeek Alfarra Downloaded from Downloaded from 10 Mohammed Ahmad Abedallah Taher Khaled AbuDagga Group A Khaled AbuAzra. Abdallah Rezq Fares AbuHashem Group B Abederhman Arga Mohammed Breka Dawood Mnefy Ibrahem Kulab Group C Each group present the case studies of this chapter

Practice 1 Mahmoud Rafeek Alfarra Downloaded from Downloaded from 11 Write A method to Find the maximum even number in array ARRAY which contains random integers from 0 To 100. Then call it in the main Method.

Practice 2 Mahmoud Rafeek Alfarra Downloaded from Downloaded from 12 Write A method to Search in array ARRAY which contains random integers from 0 To 100. Write A method to Search in array ARRAY which contains random integers from 0 To 100. The wanted values must be accepted from user and then passed to method. The wanted values must be accepted from user and then passed to method.

Next Lecture … Mahmoud Rafeek Alfarra Downloaded from Downloaded from 13 Processing string