Java Inheritance example | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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