1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ladessa [460]
3 years ago
12

Write a method drivingCost() with input parameters drivenMiles, milesPerGallon, and dollarsPerGallon, that returns the dollar co

st 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. Define that method in a program whose inputs are the car's miles/gallon and the gas dollars/gallon (both doubles). Output the gas cost for 10 miles, 50 miles, and 400 miles, by calling your drivingCost() method three times.
Computers and Technology
1 answer:
zubka84 [21]3 years ago
5 0

Answer:

The program to this question can be given as:

Program:

import java.util.*;  //import package.

public class Main  //define class main.

{

public static double drivingCost(double drivenMiles,double milesPerGallon,double dollarsPerGallon) //define method drivingCost.

{

return (drivenMiles/milesPerGallon)*dollarsPerGallon;  //return value.

}

public static void main(String[] args)  //define main method

{

double milesPerGallon,dollarsPerGallon,cost; //define variables.

Scanner ob=new Scanner(System.in);  //creating scanner class object

System.out.println("Enter milesPerGallon value :");

milesPerGallon=ob.nextDouble(); //taking input from user.

System.out.println("Enter dollarsPerGallon value :");

dollarsPerGallon=ob.nextDouble(); //taking input from user.

cost=drivingCost(10,milesPerGallon,dollarsPerGallon);  //calling a function.

System.out.println(cost); //print value.

cost=drivingCost(50,milesPerGallon,dollarsPerGallon); //calling a function.

System.out.println(cost); //print value.

cost=drivingCost(400,milesPerGallon,dollarsPerGallon); //calling a function.

System.out.println(cost); //print value.

}

}

Output:

Enter milesPerGallon value :

20.0

Enter dollarsPerGallon value :

3.1599

1.57995

7.89975

63.198

Explanation:

The above java program description can be given as:

  • In this program first, we import the package for user input. Then we define a class. In this class, we define a method that is "drivingCost()".
  • The drivingCost() method takes three parameters that are drivenMiles, milesPerGallon, and dollarsPerGallon. The return type of this method is double. In this method, we calculate and return the dollar cost to drive those miles.
  • Then we define the main method. In the main method, we declare variable and create the scanner class object and take input in the variable milesPerGallon, and dollarsPerGallon. and pass the value to the drivingCost() method. and define a variable cost that is used to take the return value of this method.
You might be interested in
The sum of these 9 numbers is 36. 2, 2, 6, 2, 1, 8, 7, 5, 3 What is the mean of these 9 numbers?
fiasKO [112]

Answer:

4

Explanation:

The mean is the sum divided by the count of numbers, so 36/9 = 4

6 0
2 years ago
Read 2 more answers
Hi, I am from India. Our brainly platform isn't so good, many of 'em keep spamming questions that I ask. US platform seems much
olga_2 [115]
It seems like a great county to visit, with many great views and tourist spots throughout.
7 0
3 years ago
How do mark somebody as brainliest??
svet-max [94.6K]

Answer:

Once more that one person answer, you will get an option next to the heart and the star that would look like a crown

Explanation:

That is how you do it.

4 0
3 years ago
An I/O-bound process ___________________________________________________ Select one: a. does not need CPU time b. spends less of
DiKsa [7]

Answer:

Spends more of its time seeking I/O operations than doing computational work.

Explanation:

The I/O bound process are depend on Input and output speed. on the other hand computational work is associated with CPU bound processes. Therefore option "C" is better option for I/O bound processes.

8 0
4 years ago
A Web browser must keep track of the sites that you have visited so that when you click the ""back"" button it will return you t
Vinil7 [7]

The data structures has a functionality that best supports the described display of previously visited sites is Linked List.

<h3>What is web browser?</h3>

A web browser is one that people uses on the internet and it helps a person to get or retrieves information from any other web or applications.

Hence, The data structures has a functionality that best supports the described display of previously visited sites is Linked List.

See options below

ArrayList or array

Queue

Stack

Priority Stack

Linked List

Learn more about Web browser from

brainly.com/question/22650550

#SPJ1

3 0
2 years ago
Other questions:
  • A virus that attaches to an executable program can do anything that the program is permitted to do.
    7·1 answer
  • Why are video texts an example of multimedia? A. They use audio and visual elements together. B. They use one type of medium to
    13·2 answers
  • What do you like most about brainly?
    13·2 answers
  • You can use this effect to break a color into a percentage of its full strength.
    13·1 answer
  • What is a googleplex?
    7·1 answer
  • Which of the following is defined in terms of their activities related to denial-of-service attacks? Cracker Script kiddie White
    6·1 answer
  • What is word length in computer​
    10·2 answers
  • Write a test program that prompts the user to enter three sides of the triangle (make sure they define an actual triangle), a co
    5·1 answer
  • Which statement is true?
    12·2 answers
  • Trebuie sa scrii niște instrucțiuni în JavaScript care adaugă în DIV lungimea HTML-ului din interiorul tag-ului cu ID​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!