Question
JAVA please leave comments thank you Task: Define a class called Vehicle that will be used to check the amount of fuel left in a
JAVA please leave comments thank you
Task: Define a class called Vehicle that will be used to check the amount of fuel left in a vehicle after traveling a certain distance. The class should have the instance variable tankSize to store the initial size of the tank and efficiency to store initial efficiency of the vehicle. Set to zero the variable fuelInTank that is used to store the initial amount of fuel in a tank. Include accessor methods that returns tankSize, efficiency and fuelInTank. Include an accessor method availableTankCapacity that calculates how much fuel can be filled depending on the fuel existing in the tank and the tanks capacity. Include a mutator method addPetrol to add petrol in the tank. This method receives number of gallons to add in the tank and checks the tanks capacity before adding the petrol. If the available tanks capacity is less than the amount of gallon received to fill in the tank, this will print an error message and adds the petrol otherwise. Also, include a method driveTo that returns what distance can be traveled with the available fuel and provided efficiency. Use your class with a test program. You should decide which variables should be public, if any. Also, define if any other method(s) are needed. A sample output of the program is given below:
Enter tank size of your car: 17 Enter the efficiency of the car: 21.5 Fuel In Tank = 0.0 Total Capacity of Tank = 17.8 Fuel Efficiency - 21.5 Available Capacity of Tank - 17.0 How much gallons of Petrol to add: 16.5 Adding 16.5 gallons fuel to the tank. Fuel In Tank - 16.5 gallons You can travel 354.75 miles with available fuel. Sample OutputStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started