ITI0011:praktikum 5 N8

Allikas: Kursused
Redaktsioon seisuga 1. oktoober 2014, kell 23:01 kasutajalt Ago (arutelu | kaastöö) (Uus lehekülg: 'Tagasi ITI0011 lehele. == Üldine == Siin on praktikumi, mis toimub teisipäeval, 30. septembril kell 8, info. Praktikumis käsitletavad teemad: * klass vs objekt * pärim...')
(erin) ←Vanem redaktsioon | Viimane redaktsiooni (erin) | Uuem redaktsioon→ (erin)
Mine navigeerimisribale Mine otsikasti

Tagasi ITI0011 lehele.

Üldine

Siin on praktikumi, mis toimub teisipäeval, 30. septembril kell 8, info.

Praktikumis käsitletavad teemad:

  • klass vs objekt
  • pärimine
  • klass kui tüüp

Exercise

Write three classes: RobotSlow, RobotFast, RobotJumpHigh. Each must be a subclass of class Robot.

Every robot has a name, starting position (just a number, starting from 0) and movement speed.

Every robot has a method "move()", which should be implemented differently for different subclasses.

RobotSlow has a fixed movement speed of 1 unit (the unit doesn't matter as all the values are measured in the same units). Its move() method just increases the robot's position by the value of movement speed (position = position + movement speed).

RobotFast has an additional property: acceleration. Its move() method increases the robot's position by movements speed + acceleration (position = position + movement speed + acceleration). Also, movements speed increases by acceleration (movement speed = movements speed + acceleration). So, if the movement speed is 10 and acceleration is 5, then after the first move() call, the movement speed is 15. After the second call the speed will be 20 etc.

RobotJumpHigh has additional properties: height - the maximum height the robot can jump - and wind speed. Its move() method increases the robot's position so that in addition to the movement speed, some additional distance is passed because of jumping. You should calculate a random value in the range [0, max height]. Now, for every height unit, the wind carries the robot further. So, the jump height you just got (a random number) will be multiplied by the wind speed. position = position + movement speed + jump height * wind speed.

Write a class for every robot and for the superclass. Write a program, which creates a list of (different) robots. For every robot in the list, call the move() method, which changes positions. If all the robots are looped through, print out the positions of the robots.

Make a loop, which makes for example 5 turns like that (so, the loop for every robot should go inside another loop, which just repeats everything). Note that the positions should not be set to zero after turns. Only in the very beginning, the positions should be 0.