Create two files to submit: Vehicle.java - Class definition, object class VehicleTester.java - Driver program, contains main() method

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

(1) Create two files to submit:

  • Vehicle.java - Class definition, object class
  • VehicleTester.java - Driver program, contains main() method

General 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 your 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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
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