Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar cost to drive those miles. All items are of type double. If the method is called with 50 20.0 3.1599, the method returns 7.89975.

Respuesta :

ijeggs

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:

import java.util.Scanner;

public class ANot {

   public static void main(String[] args) {

   Scanner in = new Scanner(System.in);

       System.out.println("Please Enter the Driven Miles");

       int drivenMiles = in.nextInt();

       System.out.println("Please Enter the Your fuel consumption in miles/gallon");

       double milesPerGallon = in.nextDouble();

       System.out.println("Please Enter the cost of fuel in Dollars/gallon");

       double dollarsPerGallon = in.nextDouble();

       double dollarCost = drivingCost(drivenMiles,milesPerGallon,dollarsPerGallon);

       System.out.println("The Total Cost in Dollars is "+dollarCost);

       }

   public static double drivingCost(int drivenMiles, double milesPerGallon,double dollarsPerGallon){

       return (drivenMiles/milesPerGallon)*(dollarsPerGallon);

   }

}

Q&A Education