A class that defines an object with instance fields (attributes) and methods(behaviors) is called an ADT: Abstract Data Type
What is an abstraction?
Can you give an example of an abstraction?
“An abstraction is a general concept or idea, rather than something concrete or tangible. In computer science, abstraction has a similar definition. It is a simplified version of something technical, such as a function or an object in a program. The goal of “abstracting” data is to reduce complexity by removing unnecessary information.”
https://techterms.com/definition/abstraction
Implement a class Car_YI with the following properties.
- A car has a certain fuel efficiency (measured in miles/gallon or liters/km—pick one) and a certain amount of fuel in the gas tank.
- The efficiency is specified in the constructor, and the initial fuel level is 0.
- Supply a method drive that simulates driving the car for a certain distance, reducing the fuel level in the gas tank, and methods getGas, returning the current fuel level, and addGas, to tank up.
Sample driver/test class:
Car_YI myBeemer = new Car_YI(29); // 29 miles per gallon myBeemer.addGas(20); // tank 20 gallons myBeemer.drive(100); // drive 100 miles System.out.println(myBeemer.getGas()); // print fuel remaining