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
olga nikolaevna [1]
3 years ago
14

2.27 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as

input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue);
Computers and Technology
2 answers:
exis [7]3 years ago
5 0

Answer:

def driving_cost(driven_miles, miles_per_gallon, dollars_per_gallon):

  gallon_used = driven_miles / miles_per_gallon

  cost = gallon_used * dollars_per_gallon  

  return cost  

miles_per_gallon = float(input(""))

dollars_per_gallon = float(input(""))

cost1 = driving_cost(10, miles_per_gallon, dollars_per_gallon)

cost2 = driving_cost(50, miles_per_gallon, dollars_per_gallon)

cost3 = driving_cost(400, miles_per_gallon, dollars_per_gallon)

print("%.2f" % cost1)

print("%.2f" % cost2)

print("%.2f" % cost3)

Explanation:

leonid [27]3 years ago
3 0

Answer:

<em>Java</em>

//////////////////////////////////////////////////////////////////////////

import java.util.Scanner;

public class MyClass {

   public static void main(String args[]) {

     double miles_gallon, gas_gallon;

     ////////////////////////////////////////////////

     System.out.print("Enter miles per gallon: ");

     Scanner myObj = new Scanner(System.in);

     miles_gallon = myObj.nextDouble();

     

     System.out.print("Enter gas dollars per gallon: ");

     gas_gallon = myObj.nextDouble();

     

     System.out.println();

     ////////////////////////////////////////////////

     double twenty_miles = 20/miles_gallon*gas_gallon;

     System.out.printf("Gas cost for 20 miles: $%.2f%n%n", twenty_miles);

     

     double seventy_five_miles = 75/miles_gallon*gas_gallon;

     System.out.printf("Gas cost for 75 miles: $%.2f%n%n", seventy_five_miles);

     

     double five_hundered_miles = 500/miles_gallon*gas_gallon;

     System.out.printf("Gas cost for 500 miles: $%.2f", five_hundered_miles);

   }

}

You might be interested in
Write a program that converts or calculates values. Use the following guidelines to write your program:
Reil [10]
Its easy just think of the program it’s a
5 0
4 years ago
In a swap you need a variable so that one of the values is not lost ? Need help
emmasim [6.3K]

Answer:

In a swap, the variable is cuttly.x

Explanation:

7 0
3 years ago
Read 2 more answers
The next generation ip version and successor to ipv4 is called what? ipv5 ipv6 iana ssl
Olenka [21]
I study IT,it was Ipv 6 in our textbook
4 0
4 years ago
Why is wearable technology important?
BaLLatris [955]
If you are in war, Wearable Technology would provide Night Vision which would spot Hostile Soldiers in forests or in the dark.
8 0
3 years ago
What is tahe difference between a cone and a prism
Natalka [10]

prism is (geometry) a polyhedron with parallel ends of the same size and shape, the other faces being parallelogram-shaped sides while cone is (label) a surface of revolution formed by rotating a segment of a line around another line that intersects the first line.

4 0
2 years ago
Other questions:
  • According to your course, two benefits of a cloud-based system are_ and_
    12·1 answer
  • In a database list, fields are displayed as _____. rows columns tables records
    10·1 answer
  • What are computer virus ? Explain in detail.In your answer include symptoms and prevention (3each)
    10·1 answer
  • What is information associated with a document to help describe that document called?
    14·1 answer
  • What will be result of below if statement.
    13·1 answer
  • Which statement is true about hacking?
    11·2 answers
  • OH GOD PLEASE HELP I CAN'T FIGURE THIS OUT-
    6·1 answer
  • In programming 5/2 is an example of what math?
    14·2 answers
  • Luke is working on a layout for a catalog. He adds cross lines on the four corners of the layout to mark out a small extra margi
    11·1 answer
  • How do I find unwanted programs on my computer?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!