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
Movie recommendations? I’m in middle school so nothing nasty bro and I don’t really like horror movies so none of those either
lbvjy [14]

Answer:

watch happy gilmore

Explanation:

5 0
3 years ago
Read 2 more answers
Computers in a medical office should be protected by which of the following security tools?
Verizon [17]
<span> it is necessary to maintain your computer on a regular basis. .... Remember these key points when recommending the Internet to a patient

Hope it helps.
</span>
8 0
4 years ago
Read 2 more answers
What is the energy conversion and the law used in the given scenario?
Natali [406]

Answer:

The correct options are;

Mechanical

Faraday

Explanation:

The principle of working of electric generators is to convert kinetic energy, which is the energy present in the spinning turbine into electrical energy. Electricity is generated by the use of the electric generators has the largest share of all forms of electricity generated electricity and it is based on Faraday's law of of induction, which states that Emf = N×(ΔФ/Δt)

Where;

Emf = The induced voltage

ΔФ = Change in magnetic flux

Δt = Change in time.

Therefore, we have;

Traditional power-generating stations do not store electrical energy. In such power stations, the original energy source spins a turbine which an electric generator. It converts <u>mechanical </u>energy into electrical energy using a fundamental principle of physics called <u>Faraday's</u> law.

3 0
3 years ago
Dogs are great pets for families because they teach children many important life lessons. (2) A dog must be walked and fed at ce
PIT_PIT [208]

The answer is A on edge. A)Just like homework and other activities, helping to take care of a dog teaches a child about responsibility.

4 0
3 years ago
Read 2 more answers
A database program helps to ____________. A. Organize, send, and retrieve e-mails quickly b. Deliver elegant presentations to a
jarptica [38.1K]

Answer: D

Explanation: D. A database is software which is designed to store massive amounts of data and organize them in such a way that information can easily be worked on (added, deleted, moved, etc...).

7 0
3 years ago
Other questions:
  • Janelle is organizing an outline for an investigative report about the benefits of taking a 30-minute walk each day. which of th
    11·2 answers
  • Why is it important to save a print copy of electronic sources
    5·1 answer
  • Read this excerpt from The Outsiders. Or I could have gotten one of the gang to come along, one of the four boys Darry and Soda
    10·2 answers
  • Assuming that a user enters 5 as the age, what is the output of the following code snippet? int age = 0; Scanner in = new Scanne
    10·1 answer
  • Someone pls help me with this question (Java)
    5·2 answers
  • 2. Which Interface uses
    7·1 answer
  • What are the values of a[k] and a[k+1] after code corresponding to the following pseudocode runs?
    9·2 answers
  • Nilsu is attempting to train a new administrative assistant on using a word processing program. Since the program is fairly comp
    15·1 answer
  • Select the correct answer from the drop-down menu.
    15·2 answers
  • Dis-cord and/or snap????????????? Im 13 ! and a girl :)))))
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!