|
1
|
- Chapter 8 introduces the technique of recursive programming.
- As you have seen, recursive programming involves spotting smaller
occurrences of a problem within the problem itself.
- This presentation gives an additional example, which is not in the book.
|
|
2
|
- To start the example, think about your favorite family car
|
|
3
|
- To start the example, think about your favorite family car
|
|
4
|
- To start the example, think about your favorite family car
|
|
5
|
- To start the example, think about your favorite family car
|
|
6
|
- To start the example, think about your favorite family car
- Imagine that the car is controlled by a radio signal from a computer
|
|
7
|
- To start the example, think about your favorite family car
- Imagine that the car is controlled by a radio signal from a computer
- The radio signals are generated by activating methods of a Car object
|
|
8
|
|
|
9
|
- When we declare a Car
- and activate the constructor, the computer makes a radio link with a car
that has a particular number.
|
|
10
|
- When we activate turnAround, the computer signals the car to turn 180
degrees.
|
|
11
|
- When we activate move, the computer signals the car to move forward one
foot.
|
|
12
|
- When we activate move, the computer signals the car to move forward one
foot.
|
|
13
|
- The isBlocked method detects barriers.
|
|
14
|
- Write a method which will move a Car forward until it reaches a
barrier...
|
|
15
|
- Write a method which will move a Car forward until it reaches a
barrier...
|
|
16
|
- Write a method which will move a Car forward until it reaches a
barrier...
|
|
17
|
- Write a method which will move a Car forward until it reaches a
barrier...
- ...then the car is turned around...
|
|
18
|
- Write a method which will move a Car forward until it reaches a
barrier...
- ...then the car is turned around...
- ...and returned to its original location, facing the opposite way.
|
|
19
|
- Write a method which will move a Car forward until it reaches a
barrier...
- ...then the car is turned around...
- ...and returned to its original location, facing the opposite way.
|
|
20
|
- Write a method which will move a Car forward until it reaches a
barrier...
- ...then the car is turned around...
- ...and returned to its original location, facing the opposite way.
|
|
21
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
|
|
22
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
23
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
24
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
25
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
26
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
27
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
28
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
29
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
30
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
31
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
32
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
33
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
34
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
35
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
36
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
37
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
38
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
39
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
40
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
41
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
42
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
43
|
- if movingCar.isBlocked( ), then the car is already at the barrier. In this case, just turn the car
around.
- Otherwise, the car has not yet reached the barrier, so start with:
|
|
44
|
|
|
45
|
- Can you write ricochet as a new method of the Car class, instead of a
separate method?
|
|
46
|
|
|
47
|
|