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
FinnZ [79.3K]
2 years ago
7

(Gas Mileage) Drivers are concerned with the mileage their automobiles get. One driver has kept track of several trips by record

ing the miles driven and gallons used for each tankful. Develop a Java application that will input the miles driven and gallons used (both as integers) for each trip. The program should calculate and display the miles per gallon obtained for each trip and print the combined miles per gallon obtained for all trips up to this point. All averaging calculations should produce floating-point results. Use class Scanner and sentinel-controlled iteration to obtain the data from the user.
Engineering
1 answer:
Effectus [21]2 years ago
6 0

Answer:

import java.util.*;

public class Main {

   

   public static void main(String[] args) {

     

       double milesPerGallon = 0;

       int totalMiles = 0;

       int totalGallons = 0;

       double totalMPG = 0;

       

       Scanner input = new Scanner(System.in);

 

       while(true){

           System.out.print("Enter the miles driven: ");

           int miles = input.nextInt();

           if(miles <= 0)

               break;

           else{

               System.out.print("Enter the gallons used: ");

               int gallons = input.nextInt();

               totalMiles += miles;

               totalGallons += gallons;

               milesPerGallon = (double) miles/gallons;

               totalMPG = (double) totalMiles / totalGallons;

               System.out.printf("Miles per gallon for this trip is: %.1f\n", milesPerGallon);

               System.out.printf("Total miles per gallon is: %.1f\n", totalMPG);

           }

       }

   }  

}

Explanation:

Initialize the variables

Create a while loop that iterates until the specified condition is met inside the loop

Inside the loop, ask the user to enter the miles. If the miles is less than or equal to 0, stop the loop. Otherwise, for each trip do the following: Ask the user to enter the gallons. Add the miles and gallons to totalMiles and totalGallons respectively. Calculate the milesPerGallon (divide miles by gallons). Calculate the totalMPG (divide totalMiles by totalGallons). Print the miles per gallon and total miles per gallon.

You might be interested in
Write a grammar for a language whose sentences start with an even and non-zero number of x’s, end with an odd number of z’s, and
sveta [45]

Answer:

GRAMMAR

S -> AB

A -> xxAyy | xxyy

B -> yyBzz | yz

EXPLANATION

A is for even number of x's followed by that number of y's

B is for odd number of y's followed by that number of z's

3 0
3 years ago
This manometer is used to measure the difference in water level between the two tanks.
SpyIntel [72]

Answer:

a) True

Explanation:

hope it helps u

3 0
2 years ago
LUNES MARTES MIÉRCOLES JUEVES VIERNES SÁBADO DOMINGO
scZoUnD [109]

Answer:

si

Explanation:

8 0
3 years ago
A(n)<br> is a safety device commonly<br> used with a slotted nut.
liraira [26]

A safety device called a cotter pin. The cotter pin fits through a hole in the bolt or part. This keeps the nut from turning and possibly coming off.

5 0
3 years ago
Oil with a density of 800 kg/m3 is pumped from a pressure of 0.6 bar to a pressure of 1.4 bar, and the outlet is 3 m above the i
Naddik [55]

Answer:

23.3808 kW

20.7088 kW

Explanation:

ρ = Density of oil = 800 kg/m³

P₁ = Initial Pressure = 0.6 bar

P₂ = Final Pressure = 1.4 bar

Q = Volumetric flow rate = 0.2 m³/s

A₁ = Area of inlet = 0.06 m²

A₂ = Area of outlet = 0.03 m²

Velocity through inlet = V₁ = Q/A₁ = 0.2/0.06 = 3.33 m/s

Velocity through outlet = V₂ = Q/A₂ = 0.2/0.03 = 6.67 m/s

Height between inlet and outlet = z₂ - z₁ = 3m

Temperature to remains constant and neglecting any heat transfer we use Bernoulli's equation

\frac {P_1}{\rho g}+\frac{V_1^2}{2g}+z_1+h=\frac {P_2}{\rho g}+\frac{V_2^2}{2g}+z_2\\\Rightarrow h=\frac{P_2-P_1}{\rho g}+\frac{V_2^2-V_1^2}{2g}+z_2-z_1\\\Rightarrow h=\frac{(1.4-0.6)\times 10^5}{800\times 9.81}+\frac{6.67_2^2-3.33^2}{2\times 9.81}+3\\\Rightarrow h=14.896\ m

Work done by pump

W_{p}=\rho gQh\\\Rightarrow W_{p}=800\times 9.81\times 0.2\times 14.896\\\Rightarrow W_{p}=23380.8\ W

∴ Power input to the pump 23.3808 kW

Now neglecting kinetic energy

h=\frac{P_2-P_1}{\rho g}+z_2-z_1\\\Righarrow h=\frac{(1.4-0.6)\times 10^5}{800\times 9.81}+3\\\Righarrow h=13.19\ m\\

Work done by pump

W_{p}=\rho gQh\\\Rightarrow W_{p}=800\times 9.81\times 0.2\times 13.193\\\Rightarrow W_{p}=20708.8\ W

∴ Power input to the pump 20.7088 kW

6 0
3 years ago
Other questions:
  • A piece of corroded steel plate was found in a submerged ocean vessel. It was estimated that the original area of the plate was
    12·1 answer
  • Which of the following machine parts always require
    12·1 answer
  • What form of joining uses heat to create coalescence of the materials?
    7·1 answer
  • your friend's parents are worried about going over their budget for th month. Which expense would you suggest is NOT a need?
    9·1 answer
  • Calculate the resistance of a circuit with 1.5 A and 120 V. Use the appropriate formula from the list of formulas on the
    9·1 answer
  • What is the locating position of the land field?​
    8·2 answers
  • below is an attempt at implementing a circle class. the class should feature a constructor that takes a starting radius, a float
    13·1 answer
  • The art of manipulating, influencing, or deceiving you into taking some action that isn’t in your best interest or in the best i
    5·1 answer
  • Why is California a good place for engineers to build suspension bridges?
    12·1 answer
  • Question is written in following attached screenshot.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!