Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Algorithm characterizations wikipedia , lookup
Java (programming language) wikipedia , lookup
Java performance wikipedia , lookup
Name mangling wikipedia , lookup
Java ConcurrentMap wikipedia , lookup
Design Patterns wikipedia , lookup
Class (computer programming) wikipedia , lookup
C Sharp syntax wikipedia , lookup
Lab08 Hurdle Racing Objective Polymorphism. The if-else control structure. Background The hurdles shown below are all one-block tall hurdles. A beeper marks the finish line. An object of the Racer class can traverse that race-course using the algorithm: while(!arg.nextToABeeper()) if(arg.frontIsClear()) arg.move(); else arg.jumpRight(); If there’s no hurdle, then move, otherwise jump over the hurdle. The else-clause jumpRight() is executed when the condition frontIsClear() is false. Now let's change the race-course so that instead of one-block tall hurdles we must jump over hurdles of any height. We do not change the algorithm above! The method arg.jumpRight() is a perfectly good command—in the abstract—to jump hurdles of any height. All we need to do is to write our own jumpRight(). In object-oriented programming we look around for a class that does approximately what we want (i.e. Racer) and the extend it. When we extend a class, we give the new class the powers that we really want—namely, how to jump hurdles of different heights. What about jumping hurdles of differing widths? Again, our original algorithm still works! All we have to do is to write a new subclass that knows how to jump these new kinds of hurdles. Racer SteepleChaseRacer BoxTopRacer Each of the classes SteepleChaseRacer and BoxTopRacer will extend Racer and override jumpRight(). Specification Consult the Unit 1 API for more information regarding the SteepleChaseRacer and BoxTopRacer classes. Create Unit1\SteepleChaseRacer.java and Unit1\BoxTopRacer.java. Implement SteepleChaseRacer and BoxTopRacer classes as described above, then compile. both the Load Unit1\Lab08.java. Compile and run. With maps “hurdle1”, “hurdle2”, and “hurdle3”, use an object of type Racer. With maps “steeple1”, “steeple2”, and “steeple3”, use a SteepleChaseRacer object. With maps “boxtop1”, “boxtop2”, and “boxtop3”, use a BoxTopRacer object.