A vehicle has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank. We need to simulate driving the vehicle for a given distance while reducing the amount of gasoline in the fuel tank. We also need to be able to check how much gas is in the tank, and we need to be able to add gasoline to the fuel tank. Build the Vehicle class with the following specifications: Instance data: Variable mpg for fuel efficiency (miles per gallon = mpg) Variable gas to save how many gallons of gas left in the tank Constructors:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Requirements

  • A vehicle has a certain fuel efficiency (measured in miles/gallon) and a certain amount of fuel in the gas tank.

  • We need to simulate driving the vehicle for a given distance while reducing the amount of gasoline in the fuel tank.

  • We also need to be able to check how much gas is in the tank, and we need to be able to add gasoline to the fuel tank. Build the Vehicle class with the following specifications:

  • Instance data:
    Variable mpg for fuel efficiency (miles per gallon = mpg)
    Variable gas to save how many gallons of gas left in the tank

  • Constructors:
    Default constructor with no parameter. Use 0 as initial values.
    Overloaded constructor with two parameters

  • Methods:
    getMPG() & setMPG()(
    getGas() & setGas()
    toString() method
    drive() to simulate that the car is driven for certain miles.

  • For example, v1.drive(100) means vehicle v1 is driven 100 miles. You need to calculate the gas cost and update the gas tank: gas = gas - miles/mpg. You also need to check if there is enough gas left since gas should not be negative. 

You need to figure out the formal parameters for the above methods.

(2) In the testing class, prompt the user for information to create two objects of the Vehicle class. Let each vehicle drive 200 miles. Print out the left gas for each vehicle.



Ex:

Vehicle 1

Enter the mpg:

40

Enter the gas left:

10.5

Vehicle 2

Enter the mpg:

35

Enter the gas left:

2.1

 

Vehicle 1 has MPG = 40, and 10.5 gallons of gas left.

Vehicle 2 has MPG = 35, and 2.1 gallons of gas left.

 

Vehicle 1 has 5.5 gallons of gas left after driving 200 miles.

Vehicle 2 does not have enough gas left to drive 200 miles.


(3) Implement the Comparable interface to make the vehicles comparable. A "bigger" vehicle has a higher mpg. 

Ex:

Based on the result of v1. compareTo(v2), you can print out:

Vehicle 1 is bigger than Vehicle 2. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Development strategies
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education