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
Determine the angular acceleration of the uniform disk if (a) the rotational inertia of the disk is ignored and (b) the inertia
lukranit [14]

Answer:

α = 7.848 rad/s^2  ... Without disk inertia

α = 6.278 rad/s^2  .... With disk inertia

Explanation:

Given:-

- The mass of the disk, M = 5 kg

- The right hanging mass, mb = 4 kg

- The left hanging mass, ma = 6 kg

- The radius of the disk, r = 0.25 m

Find:-

Determine the angular acceleration of the uniform disk without and with considering the inertia of disk

Solution:-

- Assuming the inertia of the disk is negligible. The two masses ( A & B )  are hung over the disk in a pulley system. The disk is supported by a fixed support with hinge at the center of the disk.

- We will make a Free body diagram for each end of the rope/string ties to the masses A and B.

- The tension in the left and right string is considered to be ( T ).

- Apply newton's second law of motion for mass A and mass B.

                      ma*g - T = ma*a

                      T - mb*g = mb*a

Where,

* The tangential linear acceleration ( a ) with which the system of two masses assumed to be particles move with combined constant acceleration.

- g: The gravitational acceleration constant = 9.81 m/s^2

- Sum the two equations for both masses A and B:

                      g* ( ma - mb ) = ( ma + mb )*a

                      a =  g* ( ma - mb ) / ( ma + mb )

                      a = 9.81* ( 6 - 4 ) / ( 6 + 4 ) = 9.81 * ( 2 / 10 )

                      a = 1.962 m/s^2  

- The rope/string moves with linear acceleration of ( a ) which rotates the disk counter-clockwise in the direction of massive object A.

- The linear acceleration always acts tangent to the disk at a distance radius ( r ).

- For no slip conditions, the linear acceleration can be equated to tangential acceleration ( at ). The correlation between linear-rotational kinematics is given below :

                     a = at = 1.962 m/s^2

                     at = r*α      

Where,

           α: The angular acceleration of the object ( disk )

                    α = at / r

                    α = 1.962 / 0.25

                    α = 7.848 rad/s^2                                

- Take moments about the pivot O of the disk. Apply rotational dynamics conditions:

             

                Sum of moments ∑M = Iα

                 ( Ta - Tb )*r = Iα

- The moment about the pivots are due to masses A and B.

 

               Ta: The force in string due to mass A

               Tb: The force in string due to mass B

                I: The moment of inertia of disk = 0.5*M*r^2

                   ( ma*a - mb*a )*r = 0.5*M*r^2*α

                   α = ( ma*a - mb*a ) / ( 0.5*M*r )

                   α = ( 6*1.962 - 4*1.962 ) / ( 0.5*5*0.25 )

                   α = ( 3.924 ) / ( 0.625 )

                   α = 6.278 rad/s^2

6 0
3 years ago
In order to fill a tank of 1000 liter volume to a pressure of 10 atm at 298K, an 11.5Kg of the gas is required. How many moles o
lesya [120]

Answer:

The molecular weight will be "28.12 g/mol".

Explanation:

The given values are:

Pressure,

P = 10 atm

  = 10\times 101325 \ Pa

  = 1013250 \ Pa

Temperature,

T = 298 K

Mass,

m = 11.5 Kg

Volume,

V = 1000 r

   = 1 \ m^3

R = 8.3145 J/mol K

Now,

By using the ideal gas law, we get

⇒ PV=nRT

o,

⇒ n=\frac{PV}{RT}

By substituting the values, we get

       =\frac{1013250\times 1}{8.3145\times 298}

       =408.94 \ moles

As we know,

⇒ Moles(n)=\frac{Mass(m)}{Molecular \ weight(MW)}

or,

⇒        MW=\frac{m}{n}

                   =\frac{11.5}{408.94}

                   =0.02812 \ Kg/mol

                   =28.12 \ g/mol

3 0
3 years ago
In a food processing facility, a spherical container of inner radius r1 = 40 cm, outer radius r2 = 41 cm, and thermal conductivi
Rashid [163]

Answer:

attached below

Explanation:

5 0
3 years ago
Water at 15°C is to be discharged from a reservoir at a rate of 18 L/s using two horizontal cast iron pipes connected in series
Zina [86]

Answer:

0.245 m^3/s

Explanation:

Flow rate through pipe a is 0.4 m3/s Parallel pipes have a diameter D = 30 cm => r = 15 cm = 0.15 m Length of Pipe a = 1000m Length of Pipe b = 2650m Temperature = 15 degrees Va = V / A = (0.4m3/s) / (3.14 (0.15m)^2) = 5.66 m/s h = (f(LV^2)) / D2g (fa(LaVa^2)) / Da2g = (fb(LbVb^2)) / Da2g and Da = Db; fa = fb LaVa^2 = LbVb^2 => La/Lb = Vb^2/Va^2 Vd^2 = Va^2(La/Lb) => Vb = Va(La/Lb)^(1/2) Vb = 5.66 (1000/2650)^(1/2) => 5.66 x 0.6143 = 3.4769 m/s Vb = 3.4769 m/s V = AVb = 3.14(0.15)^2 x 3.4769 m/s = 0.245 m^3/s

5 0
3 years ago
he circular stream of water from a faucet is observed to taper from a diameter of 21 mm to 12 mm in a distance of 52 cm. Determi
Gemiola [76]

Answer: 1.52 × 10^{-3} \frac{m^{3} }{s}

Explanation:

Please kindly find the attached document for the answer.

5 0
3 years ago
Other questions:
  • The Emergency Stop Button icon on the Inputs toolbar can be used to press or release the Emergency Stop button on the CNC machin
    10·1 answer
  • Water is the working fluid in a Rankine cycle. Superheated vapor enters the turbine at 8 MPa, 560°C and the turbine exit pressur
    13·1 answer
  • Why are open systems harder to study than closed systems?​
    6·1 answer
  • Unwanted resistance is being discussed.
    12·1 answer
  • The speed of an aircraft is given to be 260 m/s in air. If the speed of sound at that location is 330 m/s, the flight of the air
    6·1 answer
  • El protozoos es del reino protista?
    14·2 answers
  • A battery with an f.e.m. of 12 V and negligible internal resistance is connected to a resistor of 545 How much energy is dissipa
    9·1 answer
  • Consider the following example: The 28-day compressive strength should be 4,000 psi. The slump should be between 3 and 4 in. and
    13·1 answer
  • The figure below appeared three heat treatments processes of steel (A, B and C),
    14·1 answer
  • Risks are Not Perceived Differently from What is Happening<br> False<br> True
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!