tance 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 tw

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Java 

  • 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.

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
steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY