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


polymorphism java


Problem 1. Vehicles<br>Write a program that models 2 vehicles (Car and Truck) and will be able to simulate driving and refueling them in<br>the summer. Car and truck both have fuel quantity, fuel consumption in liters per km and can be driven given<br>distance and refueled with given liters. But in the summer both vehicles use air conditioner and their fuel<br>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<br>hole in his tank and when it gets refueled it gets only 95% of given fuel. The car has no problems when refueling and<br>adds all given fuel to its tank. If vehicle cannot travel given distance its fuel does not change.<br>Input<br>• On the first line - information about the car in format {Car (fuel quantity} {liters per km}}<br>• On the second line- info about the truck in format (Truck {fuel quantity} {liters per km}}<br>• On third line - number of commands N that will be given on the next N lines<br>• On the next N lines - commands in format<br>• Drive Car {distance}<br>• Drive Truck (distance)<br>• Refuel Car (liters}<br>• Refuel Truck (liters}<br>Output<br>After each Drive command print whether the Car/Truck was able to travel given distance in format if it's successful.<br>Print the distance with two digits after the decimal separator except trailing zeros.<br>Car/Truck travelled {distance} km<br>Orif it is not:<br>Car/Truck needs refueling<br>Finally print the remaining fuel for both car and truck:<br>Car: {liters}<br>Truck: {liters}<br>Example #1<br>Input<br>Output<br>Car travelled 9 km<br>Car 15 e.3<br>Truck 100 e.9<br>Car needs refueling<br>Truck travelled 10 km<br>4<br>Drive Car 9<br>Drive Car 30<br>Car: 54.20<br>Truck: 75.00<br>Refuel Car 50<br>Drive Truck 10<br>

Extracted text: 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} • 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 Orif 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 travelled 9 km Car 15 e.3 Truck 100 e.9 Car needs refueling Truck travelled 10 km 4 Drive Car 9 Drive Car 30 Car: 54.20 Truck: 75.00 Refuel Car 50 Drive Truck 10
Jun 03, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here