Answer:
public static double drivingCost(int drivenMiles, double milesPerGallon,double dollarsPerGallon){
return (drivenMiles/milesPerGallon)*(dollarsPerGallon);
}
Find a complete java program that prompts the user to enter this values and the calls this Method in the explanation section.
Explanation:
<em>import java.util.Scanner;</em>
<em>public class ANot {</em>
<em> public static void main(String[] args) {</em>
<em> Scanner in = new Scanner(System.in);</em>
<em> System.out.println("Please Enter the Driven Miles");</em>
<em> int drivenMiles = in.nextInt();</em>
<em />
<em> System.out.println("Please Enter the Your fuel consumption in miles/gallon");</em>
<em> double milesPerGallon = in.nextDouble();</em>
<em />
<em> System.out.println("Please Enter the cost of fuel in Dollars/gallon");</em>
<em> double dollarsPerGallon = in.nextDouble();</em>
<em />
<em> double dollarCost = drivingCost(drivenMiles,milesPerGallon,dollarsPerGallon);</em>
<em> System.out.println("The Total Cost in Dollars is "+dollarCost);</em>
<em> }</em>
<em> public static double drivingCost(int drivenMiles, double milesPerGallon,double dollarsPerGallon){</em>
<em />
<em> return (drivenMiles/milesPerGallon)*(dollarsPerGallon);</em>
<em> }</em>
<em>}</em>