2.17 LAB: Driving cost - methods Write a method drivingCost() with input parametersmilesPerGallon, dollarsPerGallon, and milesDriven that
Question:
2.17 LAB: Driving cost - methods
Write a method drivingCost() with input parametersmilesPerGallon, dollarsPerGallon, and milesDriven that returns thedollar cost to drive those miles. All items are of type double. Themethod called with arguments (20.0, 3.1599, 50.0) returns7.89975.
Define that method in a program whose inputs are the car's milesper gallon and the price of gas in dollars per gallon (bothdoubles). Output the gas cost for 10 miles, 50 miles, and 400miles, by calling your drivingCost() method three times.
Output each floating-point value with two digits after thedecimal point, which can be achieved as follows:
System.out.printf("%.2f", yourValue);
The output ends with a newline.
Ex: If the input is:
20.0 3.1599
the output is:
1.58 7.90 63.20
Your program must define and call a method:
public static double drivingCost(double milesPerGallon, doubledollarsPerGallon, double milesDriven)
An Introduction to Statistical Methods and Data Analysis
ISBN: 978-1305269477
7th edition
Authors: R. Lyman Ott, Micheal T. Longnecker