ITI0011:praktikum 5 T8
Praktikumis käsitletavad teemad:
- klass vs objekt
- pärimine
- klass kui tüüp
Exercise
There are three different type of vehicles: car, motorcycle, plane. All the vehicles have a method "move()" which will print out the text which which type of vehicle is moving and what is its max speed:
a car has a max speed of 210 km/h a plane has a max speed of 800 km/h a car has a max speed of 160 km/h
In addition, every vehicle type has a method "print()" which prints out all the information about the given vehicle:
Car: name: Audi max speed: 240 km/h doors: 5 seats: 2 Plane: name: boeing max speed: 842 km/h seats: 200 max altitude: 13000 m
A car has the following information:
- number of seats,
- max speed,
- number of doors,
- name.
A motorcycle has the following information:
- max speed,
- name,
- max power (engine).
A plane has the following information:
- number of seats,
- max speed,
- name,
- max altitude.
In addition to "move()" method, plane should have method "takeOff()" which will print the max altitude of the object:
Taking off to 13000 m.
Write class definitions for all the classes. Try to write a super class which holds common information and behaviour. Every subclass describes only information or behaviour different from the super class.
Write a simple code which will create a collection (array, list, or something else) of vehicles. Add some vehicles to the collection. Loop over the collection and for every object call "move()" and "print()" methods. In case of plane, call "takeOff()" before "move()".