Data Structures in Scheme Building data structures: Java class Circle { private double center_x, center_y, radius; Circle(double x, double y, double r)

Slides:



Advertisements
Similar presentations
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Advertisements

Inheritance Math 130 B Smith: Consider using the example in SAMS Teach Yourself C++ in 24 hours B Smith: Consider using the example in SAMS Teach Yourself.
***** SWTJC STEM ***** Chapter 4-1 cg 42 Object Oriented Program Terms Up until now we have focused on application programs written in procedural oriented.
Class Inheritance Liang, Chpt 8. X is a Y: the is-a hierarchy life-form animal person clown geometric object circle cylinder instrument trumpet piano.
OOP: Inheritance By: Lamiaa Said.
3.6 Interpreter: Recursion Recall Scheme's letrec (recursive let ): > (letrec ((fact (lambda (x) (if (zero? x) 1 (* x (fact (- x 1))))) (fact 6)) 720 Question:
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7. Data directed programming Section 2.4, pages ,2.5.2 pages (but with a different example)
Tutorial 6 February 4th/5th, 2015
Object-Oriented Programming with Java Exceptions, Strings and Things Lecture 4.
Introduction to Object- Oriented Programming with Java Spring Semester 2003 Paul Krause.
Object-Oriented Programming with Java Java with added Swing Lecture 3.
More on Objects CS 102 More, more, more on Objects.
1 Tirgul no. 3 Topics covered: H Iteration. H Defining and using classes.
Pemrograman Dasar - Data Types1 THINGS & STUFF Identifier, Variable, Constant, Data type, operator, expression, assignment, javadoc.
Liang Chapter 6 Variable scope and the keyword this.
1 Tirgul no. 4 Topics covered: H Defining classes H Documentation using javadoc H The computer memory during program execution.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 10. Data directed programming Message passing Section 2.4, pages ,2.5.2 pages (but with.
מבוא מורחב למדעי המחשב בשפת Scheme תרגול 7. Outline Symbols Data Directed Programming, Message Passing.
Objects and Classes II Chapter 6, continued. Objects can be parameters Methods take parameters: e.g. Math.sqrt(3.0); takes 3.0 as a parameter Objects.
Introduction to Java Programming, 4E Y. Daniel Liang.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Exception Handling in Java Course Lecture Slides 7 th July 2010 “ Admitting.
Appendix A.2: Review of Java and Object-Oriented Programming: Part 2 “For the object-oriented project, remember that the primary unit of decomposition.
Cs784(Prasad)L123Assg1 Assignments. cs784(Prasad)L123Assg2 l-value vs. r-value Pascal/Ada: x := x + 1 C/Java: x = x + 1 l-value = location, address, reference,
More Object Concepts Chapter 4.  Our class is made up of several students and each student has a name and test grades  How do we assign the variables.
Environment: Data type associating symbols with values { a: 4s:'foof: x.x } Interface: (empty-env) = [ Ø ] (apply-env [f] s ) = f(s) (extend-env '( s 1...
Internet Software Development Classes and Inheritance Paul J Krause.
Agenda Scope of variables Comparable interface Location class in GridWorld homework.
Plt /12/ Data Abstraction Programming Language Essentials 2nd edition Chapter 2.3 Representation Strategies for Data Types.
Circumference and Area of a Circle. Diameter Radius centre What is the formula relating the circumference to the diameter?
ICS 201 Introduction to Computer Science Problem Solving #4.
Object Oriented Programming … and other things you need to program in java.
Chapter 8. About the Midterm Exam.. Exam on March 12 Monday (Tentatively) Review on March 7 Wednesday Cover from Chapter 6 Grades will be out before spring.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
1 CS2111 Spring Instructor: David Gries You job: Come to class each week, take part. My job in first few weeks: Get you to under- stand and be facile.
Data Structures in Scheme Building data structures: Java class Circle { private double center_x, center_y, radius; Circle(double x, double y, double r)
1 OOP : main concepts Polymorphism. 2 OOP : main concepts  The main concepts:  In a superclass –public members Accessible anywhere program has a reference.
Java - Classes JPatterson. What is a class? public class _Alpha { public static void main(String [] args) { } You have been using classes all year – you.
Classes Java and other Object-Orientated Programs or OOP are based on the creation and interaction of classes. Every program in Java has at least one class.
Objects and Classes Mostafa Abdallah
Circumference Review. Review What is the relationship between a radius and a diameter? What does a circumference measure? What formulas do we use to calculate.
Chapter 7: Class Inheritance F Superclasses and Subclasses F Keywords: super and this F Overriding methods F The Object Class F Modifiers: protected, final.
Java Polymorphism. What we have learned Polymorphism is one of the three very powerful and useful mechanisms offered by OOP. What are the other two?
The Math class Java provides certain math functions for us. The Math class contains methods and constants that can be very useful. The Math class is like.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Introduction to Objects What is a constructor? Use type to create a variable Use class to create an object int x; Circle mycircle = new Circle ();
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
OOP: Inheritance. Inheritance A class can extend another class, inheriting all its data members and methods while redefining some of them and/or adding.
Object-Oriented Programming (OOP) What we did was: (Procedural Programming) a logical procedure that takes input data, processes it, and produces output.
1 Chapter 6 Programming with Objects and Classes F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive.
CS 139 Objects Based on a lecture by Dr. Farzana Rahman Assistant Professor Department of Computer Science.
The Circle. Examples (1) – (5) Determine the center and radius of the circle having the given equation. Identify four points of the circle.
Component-Based Software Engineering Java with added Swing Paul J Krause.
CIS3023: Programming Fundamentals for CIS Majors II Summer 2010 Ganesh Viswanathan Classes and Objects (contd.) Course Lecture Slides 19 May 2010.
Libraries and APIs Don’t reinvent the wheel. What’s an API? API – Application Programmers Interface –We want to use code someone else has written –API’s.
1 / 71 COP 3503 FALL 2012 SHAYAN JAVED LECTURE 4 Programming Fundamentals using Java 1.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
Object Oriented Programming COP3330 / CGS5409.  Classes & Objects  DDU Design  Constructors  Member Functions & Data  Friends and member functions.
Do Now:. Circumference What is circumference? Circumference is the distance around a circle.
INTRODUCTION Java is a true OO language the underlying structure of all Java programs is classes. Everything must be encapsulated in a class that defines.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Data Structures in Scheme
System Programming Practical Session 8 C++ classes.
10:00.
3.7 Variable Assignment Recall instance variables in Python:
Bindings, Scope, and Extent
3.6 Interpreter: Recursion
Introduction to Objects & Classes
Object-Oriented Programming and class Design
SE-1021 Software Engineering II
Chengyu Sun California State University, Los Angeles
Presentation transcript:

Data Structures in Scheme Building data structures: Java class Circle { private double center_x, center_y, radius; Circle(double x, double y, double r) { this.center_x = x; this.center_y = y; this.radius = r; } }; (define make-circle (lambda (center-x center-y radius) (list center-x center-y radius)))

Data Structures in Scheme Building data structures: Scheme - use list in a constructor function: (define make-circle (lambda (center-x center-y radius) (list center-x center-y radius)))

Data Structures in Scheme Accessing fields: use list-ref in a selector function: double getRadius () {// Java return radius; } (define get-radius; Scheme (lambda (circle) (list-ref circle 2)))

Local declaration/scope via let double area() { double pi = , r = radius; return (pi * r * r); } (define area (lambda (circle) (let ((pi ) (r (get-radius circle))) (* pi r r))))

Local declaration/scope via let (let ( (var1 val1) (var2 val2).. (varN valN) ) result )

Shortcut with letrec > (letrec ((a 3) (b (* 2 a)) (c (+ b 1))) c) 7  > (let ((a 3)) ; long version  (let ((b (* 2 a)))  (let ((c (+ b 1)))  c))) 7

Sequential execution via begin (define prompt-for-command-char (lambda (prompt) (begin (write prompt) (read)))