1 / 11

Computer Programming 2

MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE. Computer Programming 2. Lecture 2: Advanced Array Data Structure Using Methods. Prepared & Presented by: Mahmoud Rafeek Alfarra. و من يتقِ الله.

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 2: Advanced Array Data Structure Using Methods Prepared & Presented by: Mahmoud Rafeek Alfarra

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

  3. Out Lines Revision about Methods in Java Example: Search in 2-D Array X O Project. Downloaded from http://staff.cst.ps/mfarra

  4. Revision about Methods in Java Three kinds of modules exist in Java methods, classes and packages. Methods (called functions or procedures in other programming languages) allow the programmer to modularize a program by separating its tasks into self-contained units. Downloaded from http://staff.cst.ps/mfarra

  5. Revision about Methods in Java To Create Method: Access modifiers returned_typeMethod_name (Type par1, Type par2, … ) control access to a class's variables and methods. The value which the method will returned The name of method with the rules of identifiers The arguments which the method needs to perform its task Downloaded from http://staff.cst.ps/mfarra

  6. Example : Method accepts and return Method return true if the parameter x is available in in array Names else return false. Method Array True/false wanted Downloaded from http://staff.cst.ps/mfarra

  7. Solution without using Methods import javax.swing.JOptionPane; import java.math.*; public class Searchnumbers { public static void main(String[] args) { String input; int num [] = new int [10]; booleanflag= false; for (int i=0; i<5; i++) { input = JOptionPane.showInputDialog("Enter another number"); num[i]= Integer.parseInt(input); } input = JOptionPane.showInputDialog("Enter the wanted value"); int wanted = Integer.parseInt(input); int j; for ( j=0; j<5; j++) { if (num[j]==wanted) { flag = true; break; } } if (flag == true) JOptionPane.showMessageDialog(null,"the value is existed at cell "+j); else JOptionPane.showMessageDialog(null,"the value does not exist"); } } Downloaded from http://staff.cst.ps/mfarra

  8. Example : Method accepts and return In the last example: Set the type of array as string Re-programming it using Methods Downloaded from http://staff.cst.ps/mfarra

  9. Practice • Write a program to simulate the Attendance status for 10 students’ names (fname, laname), in 5 days for each student. • Write a methods to: • Calculate the sum of absent for each student. • Return the name of student who have the max number of absent days. • If the attendance of one day have 2 marks, print the marks for each student. Downloaded from http://staff.cst.ps/mfarra

  10. X O Project Using Procedural programming, 2-d array, Write a program to simulate the XO game between user and computer. Downloaded from http://staff.cst.ps/mfarra

  11. Next Lecture … Method in depth Downloaded from http://staff.cst.ps/mfarra

More Related