Computer programming 2
Download
1 / 11

Computer Programming 2 - PowerPoint PPT Presentation


  • 75 Views
  • Uploaded on

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. و من يتقِ الله.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Computer Programming 2' - karyn-sheppard


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Computer programming 2

Computer Programming 2

Lecture 2:

Advanced Array Data Structure

Using Methods

Prepared & Presented by:

Mahmoud Rafeek Alfarra


و من يتقِ الله ...

ذكر معروف الكرخي عن بكر بن خنيس رحمهما الله قال :

كيف يكون مُتَّقِيًا مَنْ لا يَدْرِي مَا يَتَّقِي

شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي

Downloaded from http://staff.cst.ps/mfarra


Out lines
Out Lines

Revision about Methods in Java

Example: Search in 2-D Array

X O Project.

Downloaded from http://staff.cst.ps/mfarra


Revision about methods in java
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


Revision about methods in java1
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


Example method accepts and return
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


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


Example method accepts and return1
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


Practice
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


X o project
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


Next lecture
Next Lecture …

Method in depth

Downloaded from http://staff.cst.ps/mfarra


ad