1 / 13

Computer Programming 2

MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE. Computer Programming 2. Lecture 3: Methods in Advanced & Practices. Prepared & Presented by: Mahmoud Rafeek Alfarra. و من يتقِ الله. كلمة التقـوى:

phuong
Download Presentation

Computer Programming 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. Out Lines 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 Downloaded from http://staff.cst.ps/mfarra

  4. Notes on Declaring and Using Methods There are three ways to call a method: Using a method name by itself to call another method of the same class such as maximum( number1, number2, number3 ) 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() Using the class name and a dot (.) to call a static method of a classsuch as Math.sqrt( 900.0 ) Downloaded from http://staff.cst.ps/mfarra

  5. Method Call Stack and Activation Records 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. Downloaded from http://staff.cst.ps/mfarra

  6. Method Call Stack and Activation Records 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. Downloaded from http://staff.cst.ps/mfarra

  7. Case Study: Random-Number Generation 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. Downloaded from http://staff.cst.ps/mfarra

  8. Case Study: Random-Number Generation A new random-number generator object can be created as follows: RandomrandomNumbers = newRandom(); Then, to generate a random int values: intrandomValue = randomNumbers.nextInt(); int randomValue = randomNumbers.nextInt( 2 ); int randomValue = randomNumbers.nextInt( 10 ); Downloaded from http://staff.cst.ps/mfarra

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

  10. In the next Lecture Mohammed Ahmad AbedallahTaher KhaledAbuDagga Group A • AbederhmanArga • Mohammed Breka • DawoodMnefy • IbrahemKulab • Group C • KhaledAbuAzra. • AbdallahRezq • Fares AbuHashem • Group B Each group present the case studies of this chapter Downloaded from http://staff.cst.ps/mfarra

  11. Practice 1 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. Downloaded from http://staff.cst.ps/mfarra

  12. Practice 2 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. Downloaded from http://staff.cst.ps/mfarra

  13. Next Lecture … Processing string Downloaded from http://staff.cst.ps/mfarra

More Related