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]
3 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]3 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
Which emission is created by the heat in the combustion process?
Musya8 [376]
Water vapor and carbon dioxide!
5 0
3 years ago
Read 2 more answers
Two sites are being considered for wind power generation. On the first site, the wind blows steadily at 7 m/s for 3000 hours per
kirill [66]

Solution :

Given :

$V_1 = 7 \ m/s$

Operation time, $T_1$ = 3000 hours per year

$V_2 = 10 \ m/s$

Operation time, $T_2$ = 2000 hours per year

The density, ρ = $1.25 \ kg/m^3$

The wind blows steadily. So, the K.E. = $(0.5 \dot{m} V^2)$

                                                             $= \dot{m} \times 0.5 V^2$

The power generation is the time rate of the kinetic energy which can be calculated as follows:

Power = $\Delta \ \dot{K.E.} = \dot{m} \frac{V^2}{2}$

Regarding that $\dot m \propto V$. Then,

Power $ \propto V^3$ → Power = constant x $V^3$

Since, $\rho_a$ is constant for both the sites and the area is the same as same winf turbine is used.

For the first site,

Power, $P_1= \text{const.} \times V_1^3$

            $P_1 = \text{const.} \times 343 \ W$

For the second site,

Power, $P_2 = \text{const.} \times V_2^3 \ W$

           $P_2 = \text{const.} \times 1000 \ W$

5 0
3 years ago
You are driving on a road where the speed limit is 35 mph. If you want to make a turn, you must start to signal at least _______
stich3 [128]
I believe it’s D) 20 feet
3 0
3 years ago
Technician A says that rear-wheel drive vehicles usually get better traction than front-wheel drive vehicles. Technician B says
Alex Ar [27]
Both a and b

Disclaimer! (90% sure)
6 0
3 years ago
Comparison of density values determines whether an item will float or sink in water. For each of the values below, determine the
geniusboy [140]

Answer:

a) the object floats

b) the object floats

c) the object sinks

Explanation:

when an object is less dense than in the fluid in which it is immersed, it will float due to its weight and volume characteristics, so to solve this problem we must find the mass and volume of each object in order to calculate the density and compare it with that of water

a)

volumen for a cube

V=L^3

L=1.53in=0.0388m

V=0.0388 ^3=5.8691x10^-5m^3=58.69ml

density=m/v

density=13.5g/58.69ml=0.23 g/ml

The wooden block floats  because it is less dense than water

b)

m=111mg=0.111g

density=m/v

density=0.111g/0.296ml=0.375g/ml

the metal paperclip floats   because it is less dense than water

c)

V=0.93cups=220.0271ml

m=0.88lb=399.1613g

Density=m/v

density=399.1613/220.027ml=1.8141g/ml

the apple sinks   because it is  denser than water

4 0
3 years ago
Other questions:
  • A cable in a motor hoist must lift a 700-lb engine. The steel cable is 0.375in. in diameter. What is the stress in the cable?
    12·1 answer
  • Is the ASUS ROG Strix B450-F Gaming amd ryzen 5 3600 ready?
    7·2 answers
  • Create a function (prob3_5) that will take inputs of vectors x and y in feet, scalar N, scalars L and W in feet and scalars T1 a
    6·1 answer
  • The specific gravity of a substance that has mass of 10 kg and occupies a volume of 0.02 m^3 is a) 0.5 b) 1.5 c) 2.5 d) 3.5 e) n
    11·1 answer
  • What is the function of engineering
    6·1 answer
  • The irreversible losses in the penstock of a hydroelectric dam are estimated to be 7 m. The elevation difference between the res
    14·1 answer
  • Which of the following would be addressed by an employer completing an EAP template?
    11·1 answer
  • A skull and crossbones pictogram indicates this kind of information about a chemical.
    14·1 answer
  • who wants points for now work just put any answer who wants points for now work just put any answer who wants points for now wor
    5·1 answer
  • A 20cm-long rod with a diameter of 0.250 cm is loaded with a 5000 N weight. If the diameter of the bar is 0.490 at this load, de
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!