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
A monatomic ideal gas undergoes a quasi-static process that is described by the function p(????)=p1+3(????−????1) , where the st
Alenkasestr [34]

A pure gas made up only of atoms. The noble gases argon, krypton, and xenon are some examples.

Concepts:

Perfect gas law: Work performed on the system: PV = nRT W = -∫PdV

Energy preservation formula: U = Q + W

Reasoning:

W = nRT ln(Vi/Vf) when the process is isothermal.

The temperature is said to be constant, and we are given n, Pfinal, and Vfinal.

Calculation information:

(A) A process that is isothermal has a constant temperature.

PV = nRT, and hence, constant

nRT = PV = 101000 Pa*25*10-3 m3

For a process that is isothermal, W = nRT ln(Vi/Vf).

W/(nRT)=3000 J/(101000 Pa*25*10-3 m3)=-1.19

(The gas produces -W of labor.)

Vi = (25*10-3 m3)/3.28 = 7.62*10-3 m3 = 7.62 L where Vf/Vi = exp(1.19) = 3.28 Vi (b) for a perfect gas PV = nRT. 101000 Pa*25*10-3 m3 = (8.31 J/K) T. T = 303.85 K.

To know more about process click here:

brainly.com/question/29310303

#SPJ4

5 0
1 year ago
Which of the following is NOT true about hydraulic valves? A. Directional control valves determine the path of a fluid in a give
Lelechka [254]

Answer: Option D is not true of hydraulic valves. A hydraulic valve is a device that can change the opening degree of liquid flow path

Explanation:

The pilot check valve allows flow of liquid in one direction and blocks flow in the opposite direction

5 0
4 years ago
Hareem and Shahad are on a road trip to Florida. They pull over to get gas, and as you may know it is sold by the gallon in the
Alona [7]

Answer:

53.3

Explanation:

4×14=56

56÷1.05=53.3

4 0
3 years ago
Many radios can be operated either by plugging them into the wall or by using batteries. How can a radio use either source of cu
ch4aika [34]

Answer:

The electric current from the batteries installed in a radio supplies direct current (DC) electricity to the radio components directly as an alternative source to the Alternating Current (AC) converted to DC by the power unit located at the radio end of the cable plugged into the wall outlet.

Explanation:

Part of the power unit in a radio includes an AC to DC converter, which is an electrical circuit that is able to convert the alternating current power input from the wall outlet into a direct current output to the radio with which the radio can work

The alternative source of electric current from the batteries installed in a radio bypasses the AC to DC converter and supplies power directly to the radio so it can also work.

5 0
3 years ago
Steam enters an adiabatic turbine at 10 MPa and 500°C and leaves at 10 kPa with a quality of 90 percent. Neglecting the changes
Anna35 [415]

Answer:

The mass flow rate of steam m=5.4 Kg/s

Explanation:

Given:

  At the inlet of turbine P=10 MPa  ,T=500 C

 AT the exit of turbine  P=10 KPa   ,x=0.9

 Required power=5 MW

From steam table

<u> At 10 MPa and 500 C:</u>

  h=3374 KJ/Kg  ,s=6.59 KJ/Kg-K  (Super heated steam table)

<u>At 10 KPa:</u>

h_g=2675.1 KJ/Kg, h_f=417.51  KJ/Kg

s_g= 7.3  KJ/Kg-K                ,s_f=1.3   KJ/Kg-K

So enthalpy of steam at the exit of turbine

h= h_f+x(h_g- h_f)

Now by putting the values

h= 417.51+0.9(2675.1- 417.51) KJ/Kg

h=2449.34  KJ/Kg

Lets take m is the mass flow rate of steam

So 5\times 10^3=m\times (3374-2449.34)

m=5.4 Kg/s

So the mass flow rate of steam m=5.4 Kg/s

8 0
4 years ago
Other questions:
  • According to the decreasing order of toughness. list the following materials (note: the steels are assumed to have no cold work
    6·1 answer
  • Define the Problem
    11·1 answer
  • The driveshaft of an automobile is being designed to transmit 238 hp at 3710 rpm. Determine the minimum diameter d required for
    8·1 answer
  • JAVA HADOOP MAPREDUCE
    13·1 answer
  • Two mass streams of the same ideal gas are mixed in a steady-flow chamber while receiving energy by heat transfer from the surro
    11·1 answer
  • Consider a CMOS inverter which has ideal transistors with the following characteristics: PMOS transistor: W/L = 2; Mobility (up)
    13·1 answer
  • A 14 inch diameter pipe is decreased in diameter by 2 inches through a contraction. The pressure entering the contraction is 28
    10·1 answer
  • If the outside diameter of a pipe is 2 m, the length of a piece of insulation wrapped around it would be a)- 628 cm b)- 12.56 m.
    15·1 answer
  • The van der Waals equation is a modification of the ideal gas equation. What two factors does this equation account for? A. (1)
    6·1 answer
  • The difference between an initial condition and a boundary condition for conduction in a solid is:___________
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!