Input  On the first line - information about the car in format {Car {fuel quantity} {liters per km}}  On the second line – info about the truck in format {Truck {fuel quantity} {liters per km}}  On third line - number of commands N that will be given on the next N lines  On the next N lines – commands in format o Drive Car {distance} o Drive Truck {distance} o Refuel Car {liters} o Refuel Truck {liters}

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

Problem 1. Vehicles
Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in
the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given
distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel
consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny
hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and
adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change.
Input
 On the first line - information about the car in format {Car {fuel quantity} {liters per km}}
 On the second line – info about the truck in format {Truck {fuel quantity} {liters per km}}
 On third line - number of commands N that will be given on the next N lines
 On the next N lines – commands in format
o Drive Car {distance}
o Drive Truck {distance}
o Refuel Car {liters}
o Refuel Truck {liters}
Output
After each Drive command print whether the Car/Truck was able to travel given distance in format if it’s successful.
Print the distance with two digits after the decimal separator except trailing zeros.
Car/Truck travelled {distance} km
Or if it is not:
Car/Truck needs refueling
Finally print the remaining fuel for both car and truck:
Car: {liters}
Truck: {liters}
Example #1
Input Output
Car 15 0.3
Truck 100 0.9
4
Drive Car 9
Drive Car 30
Refuel Car 50
Drive Truck 10
Car travelled 9 km
Car needs refueling
Truck travelled 10 km
Car: 54.20
Truck: 75.00
Page 2 of 3
Example #2
Input Output
Car 30.4 0.4
Truck 99.34 0.9
5
Drive Car 500
Drive Car 13.5
Refuel Truck 10.300
Drive Truck 56.2
Refuel Car 100.2
Car needs refueling
Car travelled 13.5 km
Truck needs refueling
Car: 113.05
Truck: 109.13

16:46 L O O
(100 4
assignment #3
Exercises: Polymorphism
Problem 1. Vehicles
Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in
the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given
distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel
consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny
hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and
adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change.
Input
On the first line - information about the car in format {Car {fuel quantity} {liters per km}}
On the second line – info about the truck in format {Truck {fuel quantity} {liters per km}}
On third line - number of commands N that will be given on the next N lines
On the next N lines – commands in format
Drive Car {distance}
Drive Truck {distance}
Refuel Car {liters}
o Refuel Truck {liters}
Output
After each Drive command print whether the Car/Truck was able to travel given distance in format if it's successful.
Print the distance with two digits after the decimal separator except trailing zeros.
Car/Truck travelled {distance} km
Or if it is not:
Car/Truck needs refueling
Finally print the remaining fuel for both car and truck:
Car: {liters}
Truck: {liters}
Example #1
Input
Output
Car 15 0.3
Car travelled 9 km
Truck 100 0.9
Car needs refueling
4
Truck travelled 10 km
Drive Car 9
Car: 54.20
Drive Car 30
Truck: 75.00
Refuel Car 50
Drive Truck 10
Page 1 of 3
Example #2
Input
Output
Car 30.4 0.4
Car needs refueling
Truck 99.34 0.9
Car travelled 13.5 km
Truck needs refueling
Drive Car 500
Car: 113.05
Drive Car 13.5
Truck: 109.13
Refuel Truck 10.300
Drive Truck 56.2
Refuel Car 100.2
Problem 2. Vehicles Extension (Bonus)
Use your solution of the previous task for starting point and add more functionality. Add new vehicle – Bus. Now
every vehicle has tank capacity and fuel quantity cannot fall below 0 (If fuel quantity become less than 0 print on
the console "Fuel must be a positive number").
Mobile view
Edit
Transcribed Image Text:16:46 L O O (100 4 assignment #3 Exercises: Polymorphism Problem 1. Vehicles Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel consumption per km is increased by 0.9 liters for the car and with 1.6 liters for the truck. Also the truck has a tiny hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change. Input On the first line - information about the car in format {Car {fuel quantity} {liters per km}} On the second line – info about the truck in format {Truck {fuel quantity} {liters per km}} On third line - number of commands N that will be given on the next N lines On the next N lines – commands in format Drive Car {distance} Drive Truck {distance} Refuel Car {liters} o Refuel Truck {liters} Output After each Drive command print whether the Car/Truck was able to travel given distance in format if it's successful. Print the distance with two digits after the decimal separator except trailing zeros. Car/Truck travelled {distance} km Or if it is not: Car/Truck needs refueling Finally print the remaining fuel for both car and truck: Car: {liters} Truck: {liters} Example #1 Input Output Car 15 0.3 Car travelled 9 km Truck 100 0.9 Car needs refueling 4 Truck travelled 10 km Drive Car 9 Car: 54.20 Drive Car 30 Truck: 75.00 Refuel Car 50 Drive Truck 10 Page 1 of 3 Example #2 Input Output Car 30.4 0.4 Car needs refueling Truck 99.34 0.9 Car travelled 13.5 km Truck needs refueling Drive Car 500 Car: 113.05 Drive Car 13.5 Truck: 109.13 Refuel Truck 10.300 Drive Truck 56.2 Refuel Car 100.2 Problem 2. Vehicles Extension (Bonus) Use your solution of the previous task for starting point and add more functionality. Add new vehicle – Bus. Now every vehicle has tank capacity and fuel quantity cannot fall below 0 (If fuel quantity become less than 0 print on the console "Fuel must be a positive number"). Mobile view Edit
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

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