0

Java Inheritance example

Can somebody give me a hand with this task? What is the approach I should take to solve the following problem?   TASK Given the 'Vehicle' class briefly described with the average consumption (liters per 100 km), extend it with the Auto class.     The Auto class manages the fuel tank   whose maximum capacity is 120 liters per car.     The Auto class must offer, in addition to the manufacturer,   the following methods:     1) The 'travel' method allows you to make a trip with   the kilometers provided as a parameter, provided that the   petrol from the tank and vehicle consumption allow it.   The kilometers traveled by each trip are stored for   support the calculation of information on the use of the car.   For simplicity, we assume a maximum of 100 trips.     2) The 'refueling' s method allows refueling   if the maximum tank capacity is not exceeded. The method   returns the number of kilometers traveled since the last   refueling done.   3) Finally, the 'average' method returns the kilometers that are averaged are covered in one journey.

21st Mar 2020, 9:25 PM
Albin Sopaj
Albin Sopaj - avatar
3 Antworten
+ 2
Hello Albin Sopaj You need to write an abstract class Vehicle. This is the super class. Here you need only to add the methods without body. For example: public void travel(double kilometer); Then write the class Auto which extends Vehicle class. Here you override each method of Vehicle and fill them with functionality. about abstract class: https://www.sololearn.com/learn/Java/2166/
21st Mar 2020, 9:49 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
public abstract class Vehicle{ } I don't think that travel() need to return a value.
21st Mar 2020, 10:16 PM
Denise Roßberg
Denise Roßberg - avatar
0
Should I write an abstract or public class? And I'm not sure if the travel method should or should not return a value (this is to say shall we use a void type) ?
21st Mar 2020, 9:54 PM
Albin Sopaj
Albin Sopaj - avatar