SUNY Geneseo Department of Computer Science
Object
Oriented Programming Concepts, Part 2
{Date}
CSci 141, Fall 2003
Prof. Doug Baldwin
Return to
List of Lectures
Previous Lecture
Misc
CodeWarrior problems with robot
- Seems to be a CodeWarrior/Mac Java misfeature
- We'll probably move to ProjectBuilder, with intro to it in tomorrow's lab
- CodeWarrior works fine on PC's
CS Learning Center
- MTWR evenings (7:00 - 8:30 or 7:00 - 9:30)
- In printer room between labs
Questions?
Turn in labs today -- any time, preferably into my hand
Intro to Design
(Chapter 2)
Expressions as algorithms for computing values
Values -- objects can contain them in member variables
Mini-Assignment:
Design an algorithm for the robot described in the book that makes the robot
move forward until it comes to a wall.
Preconditions: no obstacles between robot and the wall
Version 1:
- Command robot to walk,
- When it comes to a wall it stops
Version 2:
- Tell robot to take a step, checking as you do that robot isn't at wall
- (When robot comes to wall, it stops)
Version 3:
loop while robot can move
move
Version 4, finally, is Java Code
Postcondition: robot is on tile before wall, still facing in original direction
What does this exemplify from the reading?
- Messages, object, (class)
- Algorithm
- Steps = check to move, move
- i.e., messages to robot
- Pseudocode
- Abstraction
- Messages
- Pseudocode refinements (such "stepwise refinement" is a really
good way to develop any program or algorithm)
Next
Introduction to Theory
Consider making change using the fewest coins:
- Start with highest-valued coin,
- Give as many of that coin as you can
- Repeat with lower valued coins
Suppose there was 4-cent coin, 8 cents change
- The "greedy" algorithm doesn't work! So now how do you know there
isn't some obscure case where it doesn't work with standard US currency?
Read Sections 3.1 - 3.3 and 3.5
Next Lecture