תרגול 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()

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

Public class ABC { private int information = 0; private char moreInformation = ‘ ‘; public ABC ( int newInfo, char moreNewInfo) { } public ABC () {} public.
Peter Černo and František Mráz. Introduction Δ -Clearing Restarting Automata: Restricted model of Restarting Automata. In one step (based on a limited.
Introduction to Control Statements Presented by: Parminder Singh BCA 5 th Sem. [ Batch] PCTE, Ludhiana 5/12/ Control Statements.
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
1 Overloading vs. Overriding b Don't confuse the concepts of overloading and overriding b Overloading deals with multiple methods in the same class with.
26-Jun-15 Polymorphism. 2 Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[])
SELECTION CSC 171 FALL 2004 LECTURE 8. Sequences start end.
1 More on Classes Overview l Overloading l The this keyword l The toString method l The equals method.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
תרגול 12 מעקב אובייקטים 1. Our exams material : Course Syllabus : includes all the material.
1 Inheritance and Subclasses Instructor: Mainak Chaudhuri
1 Milena Mihail Georgia Tech. with Stephen Young, Giorgos Amanatidis, Bradley Green Flexible Models for Complex Networks.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Control Structures if else do while continue break switch case return for.
1 CS 552/652 Speech Recognition with Hidden Markov Models Winter 2011 Oregon Health & Science University Center for Spoken Language Understanding John-Paul.
Elementary Combinatorics Combinatorics  Deals with enumeration (counting) techniques and related algebra.  Basis of counting XSet |X|No. of elements.
CSE 221: Algorithms and Data Structures Lecture #10 Counting: Easy as 1, 2, C(3,1) Steve Wolfman 2009W1 1.
1 Milena Mihail Georgia Tech. “with network elements maintaining characteristic profiles” Models and Algorithms for Complex Networks “with categorical.
Counting CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Inheritance. What Is Inheritance? Familiar examples: –A family tree (individuals inherit characteristics from other individuals) –A taxonomy (classes.
Object-Oriented Programming Simple Stack Implementation.
Midterm 2 Review 1. 2 Object Oriented Programming Write a Date class. It should contain fields for day, month, year, number of months per year, and number.
FOR LOOP WALK THROUGH public class NestedFor { public static void main(String [] args) { for (int i = 1; i
1 Java linked list. Java linked list - definition ▪ Often in programming we are required to systematically store some type of information. A prime example.
1 Inheritance and Subclasses. 2 Inheritance Often we create very similar classes –Different types of triangles: equilateral, isosceles, etc. –Different.
Converting string to integer class StringToInt { public static void main (String arg[]) { // Assume arg[0] is the input string int result = 0, pos; int.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 8: Classes and Objects.
Figure **: Adjusted average student learning score against unit cost Unit Cost (fcfa) Average adjusted student learning score.
1 Advanced Programming Examples Output. Show the exact output produced by the following code segment. char[,] pic = new char[6,6]; for (int i = 0; i
Chapter 5 : Methods Part 2. Returning a Value from a Method  Data can be passed into a method by way of the parameter variables. Data may also be returned.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
1 Classes: A class is a concept of something Vehicle 4 wheels, seats, engine, windows, color…… accelerate, start, stop, turn, … attributes.
1 נתבונן בפונקציה הבאה public static int min(int[] a,int n) { int min = a[0]; for (int i = 1; (i < n ) && (i < a.length) ; i++) if (min > a[i]) min = a[i];
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
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;
28-Dec-04polymorhism.ppt1 Polymorphism. 28-Dec-04polymorhism.ppt2 signatures in any programming language, a signature is what distinguishes one function.
1 Strings and Languages Lecture 2-3 Ref. Handout p12-17.
Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013
Checking character case class characterCase { public static void main (String arg[]) { char c = ‘A’; if (isUpperCase(c)) { System.out.println(c + “ is.
CHAPTER TWO LANGUAGES By Dr Zalmiyah Zakaria.
Staples are our staple Building upon our solution.
using System; namespace Demo01 { class Program
CSC-2259 Discrete Structures
Sum of natural numbers class SumOfNaturalNumbers {
Text and Other Types, Variables
Agenda Warmup AP Exam Review: Litvin A2
Introduction to programming in java
Inside of SQL Server Indexes
LANGUAGES Prepared by: Paridah Samsuri Dept. of Software Engineering
Data Types, Type Conversions, Switch-Case, Methods
Introduction to Programming in C
Decision statements. - They can use logic to arrive at desired results
Computing Adjusted Quiz Total Score
בניית מחלקות.
null, true, and false are also reserved.
Introduction to Java Programming
An Introduction to Java – Part I, language basics
בניית מחלקות.
Introduction to Programming in C
CSE 214 – Computer Science I More on Linked Lists
Recursive GCD Demo public class Euclid {
class PrintOnetoTen { public static void main(String args[]) {
Methods and Data Passing
Scope of variables class scopeofvars {
Methods and Data Passing
Handout-4b More on Classes
Enumerating all Permutations
Presentation transcript:

תרגול 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() { return this; } public String toString() { return "x = " + this.x; } public boolean isStam1 (Stam other) { return this.x == other.x ; } // isStam1 public boolean isStam2 (Stam other) { return this.equals(other); } // isStam2 public void same (Stam other) { if (this.isStam1(other)) System.out.println(this + " same1 as " + other); else System.out.println(this + " not same1 as " + other); if (this.isStam2(other)) System.out.println(this + " same2 as " + other); else System.out.println(this + " not same2 as " + other); } // same public void print() { System.out.println(this.toString()); } public void print (Stam other) { this.same(other); } } //class Stam 2 לפניך מימוש חלקי של שלוש מחלקות : Davar,Test5 ו -.Stam public class Davar extends Stam { private int y; public int getY() { return y; } public void setY(int y) { this.y = y;} public Davar() { super(); this.y = 0; } public Davar(char c) { super(c); this.y = 0; } // Davar public Davar(char c, int num) { super(c); this.y = num; } // Davar public String toString() { return "Davar: " + super.toString(); } } // class Davar

Exam example 8, cont. public class Test5 { public static void main(String[ ] args) { Stam[ ] s = new Stam[6]; s[0] = new Stam(); s[1] = new Davar(); s[2] = new Stam( 'b‘ ); s[3] = new Davar( 'b‘ ); s[4] = new Davar( 'a', 0 ); s[5]=s[2].getStam( ); for(int i=0; i< 6; i++) s[i].print(); s[1].print(s[0]); s[2].print(s[5]); s[3].print(s[4]); } // main } // class Test 3 א. הצג את המערך s אחרי ביצוע הקטע הבא : ב. רשום את פלט הלולאה. ג. מהו פלט הקטע ?

Exam example 8- solution 4 א. תוכן מערך S לאחר ביצוע קטע של פעולה ראשית :

Exam example 8- solution,cont. 5 ב. פלט לולאת FOR : Davar: x = * same1 as x = * Davar: x = * not same2 as x = * x = b same1 as x = b x = b same2 as x = b Davar: x = b not same1 as Davar: x = a Davar: x = b not same2 as Davar: x = a ג. פלט הקטע הוא :

{a,b,c} n aaa aab aac aba abb abc aca acb acc baa bab bac bba ccc bbb bbc bca bcb bcc caa cab cac cba cbb cbc cca ccb

פתרון public static void abc(int n) { abc(n, ""); } public static void abc(int n, String s) { if (n == 0) System.out.println(s); else for (char c = 'a'; c <= 'c'; c++) abc(n-1, s+c); } public static void main(String[] args) { abc(3); {

תרגיל ממבחן

פתרון

תרגיל ממבחן

פתרון

תרגיל ממבחן

פתרון public static int change(int sum, int[] coins) } return change(sum, coins, 0); { public static int change(int sum, int[] coins, int first) } if (sum == 0) return 1; else if (sum>0 && first < coins.length) return change(sum-coins[first], coins, first) + change(sum, coins, first+1); else return 0; {