announcements introduction to object oriented programming ...ab/15-110f10/annotatednotes/lecture 23...

5
10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements Do Salons Read OOP salon and respond to questions Lab 5 is due next Saturday Simple OOP assignment Lets take a look @ Lab 4 Why do we need to read a file to an array? How do we read a file into an array? How do we search an array?

Upload: others

Post on 30-Apr-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Announcements Introduction to Object Oriented Programming ...ab/15-110F10/annotatedNotes/Lecture 23 - Introd… · 10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements

10/30/2010

1

Introduction to Object Oriented

Programming

(OOP)

Announcements� Do Salons

� Read OOP salon and respond to questions

� Lab 5 is due next Saturday

� Simple OOP assignment

Lets take a look @ Lab 4

Why do we need to read a file to

an array?

How do we read a file into an

array? How do we search an array?

Page 2: Announcements Introduction to Object Oriented Programming ...ab/15-110F10/annotatedNotes/Lecture 23 - Introd… · 10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements

10/30/2010

2

Can a function call another

function? How?

Object Oriented Programming

So far we thought of programs as

step by step instructions provided

to a computer to solve a problem

We broke the program into

________ so that we can

modularize the code and reuse the

code in different ways

Approach was good for

- printing custom tickets

- calculating monthly cable bill

- Writing a simple spell checker

- etc…

However, programmers also write

programs to manipulate physical

objects

Page 3: Announcements Introduction to Object Oriented Programming ...ab/15-110F10/annotatedNotes/Lecture 23 - Introd… · 10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements

10/30/2010

3

Physical Objects All objects belongs to Classes

Class of Robots Class of Cars

A Class is defined as a Template for

Objects An Object is an instance of a class

Objects have behaviors

Walk

Talk

Turn

Run

Behaviors are implemented by

method or functions

Page 4: Announcements Introduction to Object Oriented Programming ...ab/15-110F10/annotatedNotes/Lecture 23 - Introd… · 10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements

10/30/2010

4

Objects have State

Color

Shape

Name

Fastest speed

State of an object is represented by

variables and constants

To program real objects we need to

understand object oriented

programming

A Java program can be embedded

into a physical object to define

behaviors

Objects communicates with each

other with messagesI need a

car

You can’t drive a car

Object communication happens

through methods/functions

Some functions are public and

some are private

Page 5: Announcements Introduction to Object Oriented Programming ...ab/15-110F10/annotatedNotes/Lecture 23 - Introd… · 10/30/2010 1 Introduction to Object Oriented Programming (OOP) Announcements

10/30/2010

5

We Learn how to think about,

design and write object oriented

programs

Lets say we were asked to develop

an elevator control system

Identify objects

I love elevators

Behaviors

Elevators

Must go up and down

Must pick up

passengers

open/close doors

Passengers

Call elevatorsPick floorsClose doorOpen door

State variables

Elevators PassengersClass work

Develop Java Classes to simulate a

simple robot