1 Note: Original slides provided by www.apComputerScience.com and modified for Mr. Smith ’ s AP Computer Science A classwww.apComputerScience.com.

Slides:



Advertisements
Similar presentations
General OO Concepts Objectives For Today: Discuss the benefits of OO Programming Inheritance and Aggregation Abstract Classes Encapsulation Introduce Visual.
Advertisements

1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Mr. Wortzman.  So far, we have gotten all our input and written all our output to the console  In reality, this is somewhat uncommon  Instead, we often.
Lecture 2 Calling and Defining Methods in Java. Introduction ●Calling and defining methods ●Declaring and defining a class ●Instances of a class ●The.
Written by: Dr. JJ Shepherd
C12, Polymorphism “many forms” (greek: poly = many, morphos = form)
1 Inheritance in Java Behind the scenes: new Objects from old.
Road Map Introduction to object oriented programming. Classes
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
S A B D C T = 0 S gets message from above and sends messages to A, C and D S.
Static and Dynamic Behavior Fall 2005 OOPD John Anthony.
Fall 2005CSE 115/503 Introduction to Computer Science I1 Association Also called “knows a”. A relationship of knowing (e.g. Dog-Collar as opposed to Dog-Tail)
Fall 2007CSE 115/503 Introduction to Computer Science for Majors I1 Announcements Attendance sheet is going around – be sure you sign it! First part of.
Arrays. A problem with simple variables One variable holds one value –The value may change over time, but at any given time, a variable holds a single.
Hamming It Up with Hamming Codes CSE 461 Section Week 3.
OBJECT ORIENTED PROGRAMMING IN C++ LECTURE
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
Lecture Note 3: ASP Syntax.  ASP Syntax  ASP Syntax ASP Code is Browser-Independent. You cannot view the ASP source code by selecting "View source"
Sadegh Aliakbary Sharif University of Technology Fall 2011.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Objected Oriented Programming & Design JAVA Shishir Gupta (704) (704)
Guided Notes Ch. 9 ADT and Modules Ch. 10 Object-Oriented Programming PHP support for OOP and Assignment 4 Term project proposal C++ and Java Designer.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com Day 3.
Object-Oriented Programming. An object is anything that can be represented by data in a computer’s memory and manipulated by a computer program.
COP-3330: Object Oriented Programming Flow Control May 16, 2012 Eng. Hector M Lugo-Cordero, MS.
Chapter 12 Support for Object oriented Programming.
Karel J. Robot Tool for learning OOP (Lecture covers Ch. 1 and 2)
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com If you.
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
Exceptions, cont’d. Factory Design Pattern COMP 401 Fall 2014 Lecture 12 9/30/2014.
CS 160: Software Engineering October 22 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
1 Note: Original slides provided by and modified for Mr. Heath’s AP Computer Science A classwww.apComputerScience.com.
Class Discussion Boards. This is a tour of Manhattan’s Class Discussion Board Module. You’ll find that although there are lots of different ‘modules’
Salman Marvasti Sharif University of Technology Winter 2015.
School of Computer Science & Information Technology G6DICP - Lecture 6 Errors, bugs and debugging.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com Day 4.
Types, Implementing, Extending, Interfaces, Superclasses, Subclasses, Casting, and Access Modifiers.
1 Ch Object References a.k.a. variables Teams of Robots (e.g.) –Could have 1 robot harvest 6 rows (we’ve seen that) –Could have 3 robots each.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
CS2102: Lecture on Abstract Classes and Inheritance Kathi Fisler.
Written by: Dr. JJ Shepherd
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Karel – Chapter 6 Instructions That Repeat Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science.
OOP Basics Classes & Methods (c) IDMS/SQL News
1 Karel – Chapter 5 Conditionally Executing Instructions Note: Original slides provided by and modified for Mr. Smith’s AP Computer.
1 Note: Original slides provided by and modified for Mr. Smith’s AP Computer Science A classwww.apComputerScience.com.
Copyright 2006 Pearson Addison-Wesley, 2008, 2012 Joey Paquet 1 Concordia University Department of Computer Science and Software Engineering SOEN6441 –
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 7 : Interfaces King Fahd University of Petroleum & Minerals College of Computer.
9.1 CLASS (STATIC) VARIABLES AND METHODS Defining classes is only one aspect of object-oriented programming. The real power of object-oriented programming.
Control Structures: Conditionals, If/Else and Loops David Millard
Sections Inheritance and Abstract Classes
Some Eclipse shortcuts
Chapter 3: Using Methods, Classes, and Objects
Section 11.1 Class Variables and Methods
Polymorphism Simple but profound!.
Class Structure 16-Nov-18.
Class Structure 28-Nov-18.
Basic Object Oriented Approach
Tell me What’s Wrong with these Slides?
Class Structure 7-Dec-18.
Class Structure 2-Jan-19.
Polymorphism Professor Hugh C. Lauer CS-2303, System Programming Concepts (Slides include materials from The C Programming Language, 2nd edition, by Kernighan.
Object References a.k.a. variables
Class Structure 25-Feb-19.
String Objects & its Methods
Presentation transcript:

1 Note: Original slides provided by and modified for Mr. Smith ’ s AP Computer Science A classwww.apComputerScience.com

2 (Ch3, pg 43) What are the options for harvesting these beepers? How many robots could we use?

3 (a.k.a. variables) Teams of Robots (e.g.) –Could have 1 robot harvest 6 rows (we ’ ve seen that) –Could have 3 robots each harvest 2 rows like this: Harvester botA = new Harvester(2,2,…,…); botA.move(); botA.harvestTwoRows(); Harvester botB = new Harvester(4,2,…,…); botB.move(); botB.harvestTwoRows(); Harvester botC = new Harvester(6,2,…,…); botC.move(); botC.harvestTwoRows();

4 Could also intersperse the operations like this: // same instantiations Harvester botA = new Harvester(2,2,…,…); Harvester botB = new Harvester(4,2,…,…); Harvester botC = new Harvester(6,2,…,…); botA.move(); botB.move(); botC.move(); botA.harvestTwoRows(); botB.harvestTwoRows(); botC.harvestTwoRows(); There are 3 separate robot references in this example: botA botB botC

5 Could just use one reference like this : Harvester bot; bot = new Harvester(2,2,…,…); bot.move(); bot.harvestTwoRows(); bot = new Harvester(4,2,…,…); bot.move(); bot.harvestTwoRows(); bot = new Harvester(6,2,…,…); bot.move(); bot.harvestTwoRows(); bot is a reference we use assignment to assign a specific object to a reference instantiating (i.e constructing) 3 separate objects

6 Harvester bob; bob.harvestTwoRows(); What ’ s wrong with the above? This causes a NullPointerException error –for now, an error in Java is called an exception –NullPointerException means the reference is not pointing to anything. bob = new Harvester(2, 3,..,..); To correct the error, the object (bob) must be instantiated

7 References model what ’ s going on in the real world as well –There are lots of “ Dave ” references - but the particular object (person) one is referring to depends on context and whom one is, in particular, referring to at the moment –Well, these references are all neat and everything, but so what? Well, hold on a few more slides and you ’ ll see the power of using them - we ’ re headed toward an extremely important OO concept called Polymorphism.

8 Powerful example of Polymorphism: –pretend you are all objects - if I tell each of you to “ takeABreak() ”, you all will hear the same message but will act in different ways (some of you will sleep, some will walk out the door and eat something, some will try to leave school!, some will do work, etc.) - that ’ s polymorphism sending the same message to different objects - each individual object has a particular way to interpret (implement) the message so, back to code and a Java/Karel example…

9 remember MileWalker? (Ch3, pg 34) –we named its one method moveMile() –we could have named the method move() and then redefined what “ move ” means to a MileWalker. Again, we ’ re modeling the real world. The concept of “ move ” is different depending on what type of object is “ moving ” (think about how a dog, fish, bird, etc., “ move ” ) –so, since the general concept is the same, we often use the same name (it makes coding easy/logical) - why would you want to try to remember moveMile(), moveLegs(), moveWings(), etc. - why not just one identifier for that - move()

10 Create three separate robot classes that extend BetterRobot. Each of these robots move differently when sent the move() message. SquareRobotDiagonalLeftRobotDiagonalRightRobot