filmov
tv
Java Inheritance Vehicle Car Van Example (part1)

Показать описание
Java keywords: extends, super(), super. , static
1) A class 'Vehicle' is described by the instance variables: matriculation number, mark, owner's name and place number. Only the variable ' owner’s name’ is private and the others are public.
a) Implement the class ‘Vehicle’ and its constructor (the default constructor, and the full param constructor).
b) Add an access method to the variable owner’s name (set and get methods).
c) Add a method toString () to return a string containing all the information of the vehicle.
d) Now let's implement a class 'Car' and a class 'Van' derived from the class 'Vehicle'. The class 'Car' has an additional instance variable denoting the color of the car, its maximum speed and a static variable denoting the number of cars. Write the method that increases the maximum speed by 10%.
e) The class 'Van' has an additional instance variable denoting the length of the van and a static variable denoting the number of vans.
f) Implement the two classes 'Car' and 'Van' with their constructors.
g) Add to each class the method toString ().
h) To test your program, implement the class Driver, add the method main that does the following actions:
• Create an array of 3 Vehicles.
• Fill the array by Cars or Vans as by the user choice
• Increase the speed of Cars using the created method
• Display all information of created Vehicles
1) A class 'Vehicle' is described by the instance variables: matriculation number, mark, owner's name and place number. Only the variable ' owner’s name’ is private and the others are public.
a) Implement the class ‘Vehicle’ and its constructor (the default constructor, and the full param constructor).
b) Add an access method to the variable owner’s name (set and get methods).
c) Add a method toString () to return a string containing all the information of the vehicle.
d) Now let's implement a class 'Car' and a class 'Van' derived from the class 'Vehicle'. The class 'Car' has an additional instance variable denoting the color of the car, its maximum speed and a static variable denoting the number of cars. Write the method that increases the maximum speed by 10%.
e) The class 'Van' has an additional instance variable denoting the length of the van and a static variable denoting the number of vans.
f) Implement the two classes 'Car' and 'Van' with their constructors.
g) Add to each class the method toString ().
h) To test your program, implement the class Driver, add the method main that does the following actions:
• Create an array of 3 Vehicles.
• Fill the array by Cars or Vans as by the user choice
• Increase the speed of Cars using the created method
• Display all information of created Vehicles
Комментарии