תכנות מונחה עצמים.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

Programming Methodology (1). Implementing Methods main.
Loops –Do while Do While Reading for this Lecture, L&L, 5.7.
Picture It Very Basic Game Picture Pepper. Original Game import java.util.Scanner; public class Game { public static void main() { Scanner scan=new Scanner(System.in);
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Object Oriented 33 MCSD DORON AMIR
בתרגול הקודם הורשה: –ניתן להרחיב רק מחלקה אחת –כל מה שלא private – עובר בהורשה –המילה השמורה super –יצירת היררכיה –Object היא שורש ההיררכיה –דריסה אופרטור.
FEN KbP: Seminar 2/JML-Intro1 JML Introduktion Specifikation af en Personklasse.
האוניברסיטה העברית בירושלים
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב'
תכנות תרגול 4 שבוע : לולאות while לולאות while while (condition) { loop body } במקרה של קיום התנאי מתבצע גוף הלולאה ברגע שהתנאי לא מתקיים נצא.
תכנות תרגול 2 שבוע : שבוע שעבר כתבו תוכנית המגדירה שלושה משתנים מאתחלת אותם ל 1 2 ו 3 ומדפיסה את המכפלה שלהם את ההפרש שלהם ואת הסכום שלהם.
תכנות תרגול 6 שבוע : תרגיל שורש של מספר מחושב לפי הסדרה הבאה : root 0 = 1 root n = root n-1 + a / root n-1 2 כאשר האיבר ה n של הסדרה הוא קירוב.
נוצר ע " י ד " ר ארקדי שטיינבוק Visual Basic for Application VBA כדוגמה VBA ב - WORD.
Constructors. Defining Constructors  A constructor is a special kind of method that is designed to perform initializations, such as giving values to.
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים 1 הפניות.
אלכסנדר ברנגולץ דואר אלקטרוני: אלכסנדר ברנגולץ דואר אלקטרוני: פעולות מורפולוגיות.
מערכים עד היום כדי לייצג 20 סטודנטים נאלצנו להגדיר עד היום כדי לייצג 20 סטודנטים נאלצנו להגדיר int grade1, grade2, …, grade20; int grade1, grade2, …, grade20;
תכנות מונחה עצמים Object Oriented Programming (OOP) אתגר מחזור ב' Templates תבניות.
מבוא למדעי המחשב, סמסטר א ', תשע " א תרגול מס ' 1 נושאים  הכרת הקורס  פסאודו - קוד / אלגוריתם 1.
© המרכז להוראת המדעים האוניברסיטה העברית בירושלים
Methods & Activation Record. Recap: what’s a method?
LAB 10.
1 Scanner objects. 2 Interactive programs We have written programs that print console output. It is also possible to read input from the console.  The.
1 BUILDING JAVA PROGRAMS CHAPTER 3 THE SCANNER CLASS AND USER INPUT.
1 תרגול 2 – מבוא לתכנות JAVA. היום בתרגול : 2  משתנים וטיפוסים  אופרטורים  פונקציות מתמטיות מהמחלקה Math  המרת טיפוסים  תנאים  Debugger.
תרגול 13 חזרה 1. Exam example 8 public class Stam { private char x; public Stam() { this.x = '*'; } public Stam (char c) { this.x = c; } public Stam getStam()
FEN UCN T&B - PBA/CodeContract- Intro 1 Code Contract Introduction Specification of a Person Class.
פיתוח מערכות מידע Class diagrams Aggregation, Composition and Generalization.
1 תרגול 11: Design Patterns ומחלקות פנימיות 1 תוכנה 1.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Abstract Classes Course Lecture Slides 7 June 2010 “None of the abstract.
Library Books exercise cosc The classes Library class +ArrayList -ArrayList + Library() +initializeDefaultCategories():void +displayAllCategories():void.
Object-oriented programming ( תכנות מונחה עצמים) involves programming using objects. An object עצם)) represents an entity in the.
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
1 תרגול 11: Design Patterns ומחלקות פנימיות אסף זריצקי ומתי שמרת 1 תוכנה 1.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
WAP to find out the number is prime or not Import java.util.*; Class Prime { public static void main(string args[]) { int n,I,res; boolean flag=true;
איריס צור ברגורי יסודות – עצמים תחילה כנס מורי מדעי המחשב, תשס " ז.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
ENUMERATED TYPES Java Basics. Enumerated Type Topics Why use them? Defining an enumerated type Using an enumerated type Advanced features.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Day Programming with Methods. The “do” loop The “do” loop is a type of while loop that only does one iteration (does one loop at least) It is hardly.
מחרוזות – הטיפוס String
האוניברסיטה העברית בירושלים
Chapter 2 Clarifications
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
using System; namespace Demo01 { class Program
Operators Overloading
Introduction to Methods in java
באר-שבע 2015 יום עיון
תוכנה 1 תרגול 13 – סיכום.
חלק ה שימוש במציין שלם לערך תווי
COMPUTER 2430 Object Oriented Programming and Data Structures I
בניית מחסנית סטטית Static Stack Implementation מורים מובילים תשע"ה
תוכנה 1 תרגול 13 – סיכום.
פולימורפיזם מתקדם ממשקים בC# עריכה ועיצוב: קרן הרדי
Code Animation Examples
Recursive GCD Demo public class Euclid {
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Java Programming with Multiple Classes
Factoring if/else code
Take out a piece of paper and PEN.
Take out a piece of paper and PEN.
Consider the following code:
More on iterations using
Optional Topic: User Input with Scanner
CPSC 233 Tutorial 13 March 11/12th, 2015.
Presentation transcript:

תכנות מונחה עצמים

העצם תכונות וערכיהן בעלים יוסי לב פעולות הטיפוס תכונות בעלים פעולות דוגמה לעצם מטיפוס מחשב דוגמה לטיפוס מחשב העצם המחשב של יוסי תכונות וערכיהן בעלים יוסי לב מערכת הפעלה xp זיכרון 256Mb האם דולק לא דיסק קשיח 160G מיקום חדר עבודה פעולות הדלק כבה הגדל זיכרון ( _כמה) הטיפוס מחשב תכונות בעלים מערכת הפעלה זיכרון האם דולק דיסק קשיח מיקום פעולות הדלק כבה הגדל זיכרון ( _כמה) עזרים דידקטיים

פעולה החייבת להיות מוגדרת בכל טיפוס . בלעדיה לא ניתן לבנות עצם הגדרת הפעולות פעולה בונה פעולה החייבת להיות מוגדרת בכל טיפוס . בלעדיה לא ניתן לבנות עצם פעולות נוספות פעולות קובעות פעולות מאחזרות פעולות אחרות

דיאגרמה לתיאור טיפוס שם הטיפוס תכונות פלפל צבע: משקל: מספר - חתיכות: צור - פלפל color, weight, pieces ) ) קבע - צבע newColor ) ) קבע - משקל newWeight ) ) קבע - מספר- חתיכות newPieces ) ) פעולה בונה פעולות קובעות אחזר - צבע ( ) אחזר - משקל ( ) אחזר - מספר- חתיכות ( ) מאחזרות חתוך - כל - חתיכה - ל- 2 ( ) חתוך - כל - חתיכה - ל ( n ) אחרות עזרים דידקטיים

דיאגרמה לתיאור עצם מטיפוס פלפל העצם הפלפל שהארנב יוסי מחזיק מטיפוס פלפל תכונות וערכיהן צבע : ירוק משקל:100 גרם מספר חתיכות: 1 הפלפל בצלחת של יעל צבע : אדום משקל:120 גרם מספר חתיכות: 10 אין פעולות

אלגוריתם מילולי לביצוע פעולות צור פלפל(1, 100, "ירוק") מטיפוס פלפל בשם הפלפל-של-הארנב-יוסי הפלפל-של-הארנב-יוסי . קבע-צבע ("אדום") הפלפל-של-הארנב-יוסי . חתוך-כל-חתיכה- ל-2 הפלפל-של-הארנב-יוסי . חתוך-כל-חתיכה- ל (5) הפלפל-של-הארנב-יוסי. אחזר-מספר-חתיכות( )  num1 צור פלפל(1, 120, "צהוב") מטיפוס פלפל בשם הפלפל-של-הדוד-משה הפלפל-של- הדוד-משה . קבע-צבע ("אדום") הפלפל-של הדוד-משה . חתוך-כל-חתיכה- ל (8) הפלפל-של- הדוד-משה . אחזר-מספר-חתיכות( )  num2 הדפס num1 + num2

תכונות הטיפוס private int weight; private int pieces; import java.util.*; public class Pepper { private int weight; private int pieces; private String color; public Pepper(int weight, int pieces, String color) this.weight = weight; this.pieces = pieces; this.color = color; } public void setWeight(int newWeight) this.weight = newWeight; public void setPieces(int newPieces) this.pieces = newPieces; public void setColor(String newColor) this.color = newColor; public int getWeight() return this.weight; public int getPieces() return this.pieces; public String getColor() return this.color; public String toString() return " weight: "+ this.weight + " pieces: "+this.pieces + " color: "+this.color; public void cutIntoTwoPieces() this.pieces = pieces * 2; public void cutIntoNumPieces(int numberCuts) this.pieces = pieces * numberCuts; import java.util.*; public class Pepper { תכונות הטיפוס private int weight; private int pieces; private String color; public Pepper(int weight, int pieces, String color) פעולה בונה this.weight = weight; this.pieces = pieces; this.color = color; } פעולות מאחזרות public int getWeight() { return this.weight; } public int getPieces() return this.pieces; public String getColor() return this.color; פעולות חישוביות public void cutIntoTwoPieces() { this.pieces = pieces * 2; } public void cutIntoNumPieces(int numberCuts) this.pieces = pieces * numberCuts; פעולות קובעות public void setWeight(int newWeight) { this.weight = newWeight; } public void setPieces(int newPieces) this.pieces = newPieces; public void setColor(String newColor) this.color = newColor; פעולת הדפסה public String toString() { return " weight: "+ this.weight + " pieces: "+this.pieces + " color: "+this.color; }

import java.util.*; public class TestPepper { static Scanner reader = new Scanner(System.in); public static void main(String[] arg) בניית עצם בשם Pepper p1= new Pepper(46,5,"red"); p1 הדפסת הערכים של תכונות העצם p1 System.out.println(p1); פעולה המשנה וקובעת את מספר החתיכות של העצם p1 p1.setPieces(9); פעולה המאחזרת את הצבע של העצם p1 System.out.println(p1.getColor()); פעולה המחשבת מחדש את חתיכות העצם p1 p1.cutIntoNumPieces(7); הדפסת הערכים של תכונות העצם p1 System.out.println(p1); }