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
describe at least five ways in which information technology can help studying subjects other than computing​
Oksana_A [137]

Answer:

I'd that IT can help in a great many different fields like

Mathematics, in a manner of solving complex math equations

Statistics, in a manner of creating complex graphs with millions of points

Modeling, in a manner of creating models from scratch, either for cars, personal projects or characters for video games and entertainment

Advertising, in a manner of using IT to create not only the advertisements themselves but also, spreading that advertisement to millions in a single click

Music/Audio, in a manner of creating new sounds and music that wouldn't be able to work in any practical manner

Explanation:

4 0
3 years ago
In scratch coding what can I do with "when I recive messeage 1 "
Ilya [14]

Answer:

Messages can be sent from other parts of your program.

The 'When receive message...' block allows you to receive those messages and start another part of your program. That way you can even have parts of you program run in parallel.

3 0
3 years ago
____ are the computers that store network software and shared or private user files.
kodGreya [7K]
Servers <span>are the computers that store network software and shared or private user files.</span>
3 0
4 years ago
Store shelves are empty during periods of Excess Demand. What is another term for Excess Demand?
Sunny_sXe [5.5K]
The answer is B, Shortage
6 0
3 years ago
Create a cell reference in a format by typing in the cell name or
Neko [114]

Answer:

D. Create a cell reference in a formula by typing in the cell name or clicking the cell.

Further Explanation:

To create a cell reference in a formula the following procedure is used:

First, click on the cell where you want to add formula.

After that, in the formula bar assign the equal (=) sign.

Now, you have two options to reference one or more cells. Select a cell or range of cells that you want to reference. You can color code the cell references and borders to make it easier to work with it. Here, you can expand the cell selection or corner of the border.

Again, now define the name by typing in the cell and press F3 key to select the paste name box.

Finally, create a reference in any formula by pressing Ctrl+Shift+Enter.

6 0
3 years ago
Other questions:
  • Software that interprets commands from the keyboard and mouse is also known as the A.hard drive.B.operating system.C.desktop or
    7·2 answers
  • To add text into a SmartArt graphic, a user will need to _____.
    14·1 answer
  • Which of the following is a preferable method to secure wireless access in a SOHO?
    12·1 answer
  • When subscripts are used to specify character positions in a string the first character subscript is 0?
    5·1 answer
  • Andrew wants to create a website for his college. Which web-based programming language should he use?
    11·2 answers
  • What is institutional advertising focused on promoting?
    8·1 answer
  • What factors should you consider when buying a hard drive?
    8·1 answer
  • The first step when entering data is _
    6·1 answer
  • All of these (except the ______) go unnoticed by the computer
    7·1 answer
  • Fortnight on sat 530-10 my name is TTV BTW laggking_12
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!