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
An open vat in a food processing plant contains 500 L of water at 20°C and atmospheric pressure. If the water is heated to 80°C,
tester [92]

Answer:

percentage change in volume is 2.60%

water level rise is 4.138 mm

Explanation:

given data

volume of water V = 500 L

temperature T1 = 20°C

temperature T2 = 80°C

vat diameter = 2 m

to find out

percentage change in volume and how much water level rise

solution

we will apply here bulk modulus equation that is ratio of change in pressure   to rate of change of volume to change of pressure

and we know that is also in term of change in density also

so

E = -\frac{dp}{dV/V}  ................1

And -\frac{dV}{V} = \frac{d\rho}{\rho}   ............2

here ρ is density

and we know ρ  for 20°C = 998 kg/m³

and ρ  for 80°C = 972 kg/m³

so from equation 2 put all value

-\frac{dV}{V} = \frac{d\rho}{\rho}

-\frac{dV}{500*10^{-3} } = \frac{972-998}{998}

dV = 0.0130 m³

so now  % change in volume will be

dV % = -\frac{dV}{V}  × 100

dV % = -\frac{0.0130}{500*10^{-3} }  × 100

dV % = 2.60 %

so percentage change in volume is 2.60%

and

initial volume v1 = \frac{\pi }{4} *d^2*l(i)    ................3

final volume v2 = \frac{\pi }{4} *d^2*l(f)    ................4

now from equation 3 and 4 , subtract v1 by v2

v2 - v1 =  \frac{\pi }{4} *d^2*(l(f)-l(i))

dV = \frac{\pi }{4} *d^2*dl

put here all value

0.0130 = \frac{\pi }{4} *2^2*dl

dl = 0.004138 m

so water level rise is 4.138 mm

8 0
3 years ago
You are given a noninverting 741 op-amp with a dc-gain of 23.6 dB. The input signal to this amplifier is;Vin(t) = (0.18)∙cos(2π(
Vsevolod [243]

Answer:

Output voltage equation is V_{out} (t) = 2.72 \cos (2\pi (57000)t +18.3)

Explanation:

Given:

dc gain A = 23.6 dB

Input signal V_{in} (t) = 0.18 \cos (2\pi (57000)t +18.3)

Now convert gain,

A = 10^{\frac{23.6}{20} } = 15.13

DC gain at frequency f = 0 is given by,

  A = \frac{V_{out} }{V_{in} }

V_{out} =AV_{in}

V_{out} = 15.13 \times   0.18 \cos (2\pi (57000)t +18.3)

At zero frequency above equation is written as,

V_{out} = 2.72 \times \cos 18.3

V_{out} = 2.72

Now we write output voltage as input voltage,

V_{out} (t) = 2.72 \cos (2\pi (57000)t +18.3)

Therefore, output voltage equation is V_{out} (t) = 2.72 \cos (2\pi (57000)t +18.3)

7 0
3 years ago
A thick steel slab ( 7800 kg/m3 , c 480 J/kg K, k 50 W/m K) is initially at 300 C and is cooled by water jets impinging on one o
Nutka1998 [239]

Answer:

1791 secs  ≈ 29.85 minutes

Explanation:

( Initial temperature of slab )  T1 = 300° C

temperature of water ( Ts ) = 25°C

T2 ( final temp of slab ) = 50°C

distance between slab and water jet = 25 mm

<u>Determine how long it will take to reach T2</u>

First calculate the thermal diffusivity

∝  = 50 / ( 7800 * 480 ) = 1.34 * 10^-5 m^2/s

<u>next express Temp as a function of time </u>

T( 25 mm , t ) = 50°C

next calculate the time required for the slab to reach 50°C at a distance of 25mm

attached below is the remaining part of the detailed solution

5 0
3 years ago
A train consists of a 50 Mg engine and three cars, each having a mass of 30 Mg . If it takes 75 s for the train to increase its
ohaa [14]

Answer:

T = 15 kN

F = 23.33 kN

Explanation:

Given the data in the question,

We apply the impulse momentum principle on the total system,

mv₁ + ∑\int\limits^{t2}_{t1} {Fx} \, dt = mv₂

we substitute

[50 + 3(30)]×10³ × 0 + FΔt = [50 + 3(30)]×10³ ×  ( 45 × 1000 / 3600 )  

F( 75 - 0 ) =  1.75 × 10⁶

The resultant frictional tractive force F is will then be;

F =  1.75 × 10⁶ / 75

F = 23333.33 N

F = 23.33 kN

Applying the impulse momentum principle on the three cars;

mv₁ + ∑\int\limits^{t2}_{t1} {Fx} \, dt = mv₂

[3(30)]×10³ × 0 + FΔt = [3(30)]×10³ ×  ( 45 × 1000 / 3600 )  

F(75-0) = 1.125 × 10⁶

The force T developed is then;

T =  1.125 × 10⁶ / 75

T = 15000 N

T = 15 kN

7 0
3 years ago
For a column that is pinned at both ends, the critical buckling load can be calculated as, Pcr = π2 E I /L^2 where E is Young's
gulaghasi [49]

When a slender member is subjected to an axial compressive load, it may fail by a ... Consider a column of length, L, cross-sectional Moment of Inertia, I, having Young's Modulus, E. Both ends are pinned, meaning they can freely rotate ... p2EI L2 ... scr, is the Euler Buckling Load divided by the columns cross-sectional area

6 0
3 years ago
Other questions:
  • Material with hardness of 220 Vickers is harder than material with a hardness of 180 Vickers. a)-True b)- False
    8·1 answer
  • An AC sine wave has an effective value of 100V what’s the peak value of the waveform
    6·1 answer
  • Why do we write proton ions first before electron ions? <br>​
    10·1 answer
  • For an irreversible isothermal process occured in a system with temperature T, which following expression best evaluates the cha
    11·1 answer
  • 1 kg of oxygen is heated from 20 to 120°C. Determine the amount of heat transfer required when this is done during a (a) constan
    7·1 answer
  • Given two alphabet strings str1 and str2. You can change the characters in str1 to any alphabet characters in order to transform
    8·1 answer
  • A 360 kg/min stream of steam enters a turbine at 40 bar pressure and 100 degrees of superheat. The steam exits the turbine as a
    14·1 answer
  • Which of the following parts tells the transmission how fast or slowly a vehicle is going? A) pump
    5·1 answer
  • A single-phase load is located 2800 ft from its source. The load draws a current of 86 A and operates on 480 V. The maximum volt
    10·1 answer
  • Question 2
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!