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

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)

Step by Step Solution

3.47 Rating (160 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public static void mainString args Scanner sc new ScannerSystemin double mpg scnex... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!