For Wednesday Read Becker, sections 2.3-2.6 (skip 2.3.4 and 2.3.6) - - PowerPoint PPT Presentation

for wednesday
SMART_READER_LITE
LIVE PREVIEW

For Wednesday Read Becker, sections 2.3-2.6 (skip 2.3.4 and 2.3.6) - - PowerPoint PPT Presentation

For Wednesday Read Becker, sections 2.3-2.6 (skip 2.3.4 and 2.3.6) Recommended practice problems: chapter 2, problems 1-3 Planting Flowers You have a square enclosure. You want to have a robot plant flowers (Things) around the


slide-1
SLIDE 1

For Wednesday

  • Read Becker, sections 2.3-2.6 (skip 2.3.4 and

2.3.6)

  • Recommended practice problems: chapter 2,

problems 1-3

slide-2
SLIDE 2

Planting Flowers

  • You have a square enclosure. You want to

have a robot plant flowers (Things) around the enclosure. See below. Questions: How many walls are there? How are they positioned? Where do the flowers come from?

slide-3
SLIDE 3

Beyond Robots

  • Objects are used in all contexts in Java

programs.

  • The same patterns are used to develop

GUI (Graphical user interface) programs as to develop Robot programs.

  • However, the classes we use are different.
slide-4
SLIDE 4

Sample Simple GUI

  • Use the JFrame, JLabel, JTextField, and

JTextArea classes to produce a program that creates a window that looks like a browser window (sort of).

slide-5
SLIDE 5

Adding Services

  • What are some advantages to being able

to create “customized” robots?

slide-6
SLIDE 6

Vocabulary

  • Superclass --- subclass
  • Parent --- child
  • Base class --- derived class
  • Extends
  • Inherits from
slide-7
SLIDE 7

Class Diagrams

slide-8
SLIDE 8

Extended Class Pattern

slide-9
SLIDE 9

Constructors

  • What’s the purpose of a constructor?
slide-10
SLIDE 10

Writing Constructors

public class ExperimentRobot extends Robot { // A constructor to initialize the ExperimentRobot public ExperimentRobot(City aCity, int aStreet, int anAvenue, Direction aDirection) { super(aCity, aStreet, anAvenue, aDirection); } // Another constructor to initialize the ExperimentRobot to be in a standard position. public ExperimentRobot(City aCity) { super(aCity, 0, 0, Direction.EAST); } // The new services offered by an ExperimentRobot will be inserted here. } Usage: ExperimentRobot lisa = new ExperimentRobot(austin, 3, 2, Direction.SOUTH); ExperimentRobot larry = new ExperimentRobot(austin);

slide-11
SLIDE 11

Creating New Services

slide-12
SLIDE 12

Flow of Control

  • What happens when we actually call a

method?

slide-13
SLIDE 13

RobotSE

  • More capable version of Robot
  • Extension vs. Modification
slide-14
SLIDE 14
slide-15
SLIDE 15

Planting Flowers Again

  • We’re going to redo the planting flowers

problem with two modifications:

– Create and use a GardenerBot that has a method plantFlowers, which plants all the flowers. – Create an extended version of City called Garden that automatically includes the four walls.