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
Furkat [3]
3 years ago
10

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.
Computers and Technology
1 answer:
aleksklad [387]3 years ago
8 0

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>

You might be interested in
Write the definition of a function printAttitude , which hasan int parameter and returns nothing. The function prints amessage t
erastova [34]

Answer:

The function definition to this question can be given as:

Function definition:

void printAttitude(int x1) //define function printAttitude.

{

//nested else-if statements

if(x1==1)

 //if block

cout<<"disagree"<<endl;

//message

else if(x1==2)

 //else if block  

cout<<"no opinion"<<endl;

//message

else if(x1==3)

 //else if block

cout<<"agree"<<endl;

//message

else

cout<<" ";

}

Explanation:

In the above method definition firstly, we define a method that is "printAttitude". In this method, we pass an integer variable that is "x1". This function does not return any value because its return type is void. In this method, we use nested else-if statements. The description of these conditions can be given as:

  • In the if block we check the variable x1 value is equal to 1 If this condition is true. It will print "disagree" otherwise it will go to else-if block.  
  • In the else-if block, we check the variable x1 value is equal to 2 if the condition is true. It will print "no opinion". otherwise, we will go to another else-if block.
  • In this block, we check the variable x1 value is equal to 3 if this condition is true. It will print "agree".otherwise it will go to else block.
  • In the else block it will print nothing.
6 0
4 years ago
Write the following C function and main function;
Rina8888 [55]

Answer:

The program to this question can be given as:

Program:

#include <stdio.h> //include header files.

#include <limits.h>

//declaration of function

void find_three_smallest(int a[], int n, int *small, int *second_smallest, int *third_smallest);

//definitation of function

void find_three_smallest(int a[], int n, int *smallest, int *second_smallest, int *third_smallest)

{//function body.

int i, first_number, second_number, third_number;       //define variable.

// There should atleast be three values

if (n < 3)       //check condition.

{

printf(" Invalid Input ");      //print message.

return;

}

first_number = second_number = third_number = INT_MAX;

for (i = 0; i < n ; i ++)    //Using loop  

{

//conditional statements.

// If current element is smaller than first then update all

if (a[i] < first_number)            

{

third_number = second_number;

second_number = first_number;

first_number = a[i];

}

else if (a[i] < second_number )

{

third_number = second_number;

second_number = a[i];

}

else if (a[i] < third_number )

{

third_number = a[i];

}

}

//print values.

printf("The smallest value =%i\n",first_number);

printf("Second_smallest value =%i\n",second_number);

printf("Third_smallest value =%i\n",third_number);    

}

//main method

int main()

{

int num, small, second_small, third_small; //define variable.

int x[6] = {1,3,4,5,1,2};         //define 1-D array.

num = sizeof(x)/sizeof(x[0]);  

find_three_smallest(x,num ,&small, &second_small, &third_small);       //calling function.

return 0;

}

Output:

The smallest value = 1

Second_smallest value = 1

Third_smallest value = 2

Explanation:

In the above C language program firstly we declare a function that's name is already given in the question.  

In this function we define the variable that takes all value from the main function and checks that the given values(numbers) are greater then 3. if the value is greater then 3 functions arranged values and finds the smallest, second smallest and third smallest value and print it. In the main function, we define a 1_D array. In that array, we assign the value and pass the value to the function. In the next line, we calling the function.  

8 0
3 years ago
The ______ layer adds a header to the packet coming from the upper layer that includes the logical addresses of the sender and r
rjkz [21]

Answer: Network layer

Explanation: Network layer the third layer of the OSI model architecture which is focused on the operation of making the logical paths for the data packets so that they can flow.

The packets carry the addresses of the sender port and the destination port which is added to the header of the packet and then the path is established accordingly so that the packet can travel.

4 0
3 years ago
You're researching information about titanium bike frames. Which Web site is probably the least biased? The web site of a nation
Alexxx [7]
The website of a National Bike Museum would give you information about all different kinds of bikes. 

A local Bike shop would likely be biased to try to get you to buy from them. 

Answer) The website of a National Bike Museum 
5 0
3 years ago
Under which access control system is each piece of information and every system resource (files, devices, networks, and so on) l
Pani-rosa [81]

Answer:

C. Mandatory access control

Explanation:

In the implementation of computer security, the mandatory access control (MAC) refers to the implementation of a security feature by operating systems. In this method, individual resource owners’ are unable to deny or grant permissions to a resources contained in a file. The criteria in a MAC when defined by the system administrator is implemented and enforced by the OS.

7 0
3 years ago
Other questions:
  • What will be the output of “AAAAMMMMMHHHVV” using a file compression technique?
    10·1 answer
  • Drag the tiles to the correct boxes to compete the pairs.
    12·2 answers
  • A _____ is a collection of binary digits, including message data and control characters for formatting and transmitting, sent fr
    10·1 answer
  • Using truth table, prove that:<br><br> (A + B). C = (A . C)+ (B .C) ?
    7·1 answer
  • Explain URL's parts with the help of an example.​
    10·1 answer
  • Briefly tell me what a PUT request does
    11·1 answer
  • You are the IT security administrator for a small corporate network. You would like to use Group Policy to enforce settings for
    14·1 answer
  • pharmaceutical company is using blockchain to manage their supply chain. Some of their drugs must be stored at a lower temperatu
    5·2 answers
  • List how much hard disk capacity you recommend, and write a sentence explaining why.
    8·1 answer
  • Write code which takes two inputs from the user, a number of sides followed by a side length, then creates a regular polygon wit
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!