Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION &

Slides:



Advertisements
Similar presentations
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.
Advertisements

Java POWERED BY: ARVIND DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING RADHA GOVIND GROUP OF INSTITUTIONS,MEERUT.
Arrays. What is an array An array is used to store a collection of data It is a collection of variables of the same type.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
CS 106 Introduction to Computer Science I 02 / 18 / 2008 Instructor: Michael Eckmann.
CS 106 Introduction to Computer Science I 10 / 04 / 2006 Instructor: Michael Eckmann.
03/16/ What is an Array?... An array is an object that stores list of items. Each slot of an array holds an individual element. Characteristics.
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.
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 3: Methods in Advanced & Practices Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION.
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
G51PRG-Sem2 A Reality Check a sort of quiz Dave Elliman.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 7 Decision Making : selection statements.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
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.
Computer Programming 2 Lecture 5: String Processing Part b: Class StringTokenizer Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
An Introduction to Java – Part 1 Dylan Boltz. What is Java?  An object-oriented programming language  Developed and released by Sun in 1995  Designed.
Introduction To Programming Information Technology , 1’st Semester
OBJECTS FOR ORGANIZING DATA -- As our programs get more sophisticated, we need assistance organizing large amounts of data. : array declaration and use.
Mixing integer and floating point numbers in an arithmetic operation.
Lecture 101 CS110 Lecture 10 Thursday, February Announcements –hw4 due tonight –Exam next Tuesday (sample posted) Agenda –questions –what’s on.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 9 & 10 Repetition Statements.
Array Objectives To understand the concept of arrays To understand the purpose to which we use arrays. To be able to declare references to arrays. To be.
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.
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.
Building java programs, chapter 3 Parameters, Methods and Objects.
How do you do the following? Find the number of scores within 3 points of the average of 10 scores? What kind of a tool do you need? Today’s notes: Include.
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.
An Introduction to Java – Part 1 Erin Hamalainen CS 265 Sec 001 October 20, 2010.
CS 180 Recitation 7 Arrays. Used to store similar values or objects. An array is an indexed collection of data values of the same type. Arrays are the.
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.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
Using Java MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE Lecture 18 Recursion & Pointers in Java.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
DATA STRUCTURE Presented By: Mahmoud Rafeek Alfarra Using C# MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY KHANYOUNIS- PALESTINE.
Methods. Creating your own methods Java allows you to create custom methods inside its main body. public class Test { // insert your own methods right.
Object Oriented Programming Lecture 2: BallWorld.
Introduction to Programming using Java Day 3 and 4 Java Language Basics Review The “For” loop Subroutines The “String” class.
Presented By: Mahmoud Rafeek Alfarra
Presented By: Mahmoud Rafeek Alfarra
Computer Programming Methodology Input and While Loop
An Introduction to Java – Part I
Introduction To Programming Information Technology , 1’st Semester
Part a: Fundamentals & Class String
An Introduction to Java – Part I, language basics
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
class PrintOnetoTen { public static void main(String args[]) {
Scope of variables class scopeofvars {
Presented By: Mahmoud Rafeek Alfarra
Arrays in Java.
Introduction To Programming Information Technology , 1’st Semester
C Programming Pointers
Presented By: Mahmoud Rafeek Alfarra
Presentation transcript:

Computer Programming 2 Lecture 9: Object Oriented Programming Array Of Objects Prepared & Presented by: Mahmoud Rafeek Alfarra MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE

و من يتقِ الله... عليك بتقوى الله ان كنت غافلا يأتيك بالأرزاق من حيث لا تدري فكيف تخاف الفقر والله رازقا فقد رزق الطير والحوت في البحر ومن ظن أن الرزق يأتي بقوة ما أكل العصفور شيئا مع النسر تزول عن الدنيا فإنك لا تدري إذا جن عليك الليل هل تعيش إلى الفجر فكم من صحيح مات من غير علة وكم من سقيم عاش حينا من الدهر وكم من فتى أمسى وأصبح ضاحكا وأكفانه في الغيب تنسج وهو لا يدري فمن عاش ألفا وألفين فلا بد من يوم يسير إلى القبر Mahmoud Rafeek Alfarra 2 Downloaded from قال الشاعر عن التقـوى:

Out Lines Mahmoud Rafeek Alfarra Downloaded from Downloaded from 3 What is Array of object? Why is Array of objects? How to create an array of objects? Example

What is Array of object? Mahmoud Rafeek Alfarra Downloaded from Downloaded from 4 So far we have looked at an array of primitive types. integers could also use doubles, floats, characters… Often want to have an array of objects Students, Books, Loans ……

Why is Array of objects? Mahmoud Rafeek Alfarra Downloaded from Downloaded from 5 Book Class Create objects Obj1 Obj2 Obj3 Obj n How to search, sort, Print all ….? Book Class Create objects Obj1 Obj2 Obj3 Obj n …. [0] [1] [2] [n] By index of array We can make all the manipulation operations

How to create an array of objects? Mahmoud Rafeek Alfarra Downloaded from Downloaded from Declare the array private Student studentList[]; //this declares studentList 2.Create the array studentList = new Student[10]; this sets up 10 spaces in memory that can hold references to Student objects 3. Create Student objects and add them to the array: studentList[0] = new Student("Cathy", "Computing");

How to create an array of objects? Mahmoud Rafeek Alfarra Downloaded from Downloaded from 7 Array of employees MainClass EmployeeClass 4. Manage 2. Create objects of Obj 1 Obj 2 Obj 3 Obj 4 3. objects 1. Create objects of

Example: Array Of PC Mahmoud Rafeek Alfarra Downloaded from Downloaded from public class PC { 2. private static int PCcounter; 3. private static String code; 4. private static String YOM; 5. private static int cost; 6. public PC() { 7. PCcounter++; 8. code = "no code"; 9. YOM = "1990"; } 10. public PC(String code, String YOM, int cost) { 11. PCcounter++; 12. this.code =code; 13. this.YOM = YOM; 14. this.cost = cost; } 15. public void info(){ 16. System.out.println(" "); 17. System.out.println("Code: "+code+"\nYOM: "+YOM+"\ncost: "+cost); } }

Example: Array Of PC Mahmoud Rafeek Alfarra Downloaded from Downloaded from public class Record { 2. PC [] rec = new PC[50]; 3. private int count; 4. public Record() { 5. count =0; } 6. public void insert(String code, String YOM, int cost){ 7. if(count<50){ 8. PC p = new PC(code, YOM,cost); 9. rec[count] = p; 10. count++;} 11. else System.out.println("Sorry, The record is complete"); } 12. public void insert(){ 13. if(count<50){ 14. PC p = new PC(); 15. rec[count] = p; 16. count++;} 17. else System.out.println("Sorry, The record is complete"); } 18. public void PrintAll(){ 19. System.out.println("Count of PC: "+count); 20. for(int i =0; i<count; i++) 21. rec[i].info(); } }

Example: Array Of PC Mahmoud Rafeek Alfarra Downloaded from Downloaded from public class RecordPC { public static void main(String[] args) { Record rec1 = new Record(); 6. rec1.insert("pc123","2010",450); 7. rec1.insert("pc124","2010",455); 8. rec1.insert("pc125","2010",460); 9. rec1.PrintAll(); 10. } 11. }

Next Lecture … Mahmoud Rafeek Alfarra Downloaded from Downloaded from 11 Java Applet