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 engineering drawing shows the: (A) dimensions, tolerances, cost, and sales or use volume of a component.(B) dimensions, toler
Leto [7]

Answer:

(B) dimensions, tolerances, materials, and finishes of a component.

Explanation:

An engineering drawing :

  An  engineering drawing is a technical drawing which draws the actual component .

An engineering drawing shows

1. Materials

2.Dimensions

3.Tolerance

4.Finishes of a component

Engineering drawing does not shows any information about the cost of component.

So the option B is correct.

3 0
3 years ago
A 4-m-high and 6-m-long wall is constructed of twolarge 2-cm-thick steel plates (k 5 15 W/m·K) separated by1-cm-thick and 20-cm
Flura [38]

Answer:

fart

Explanation:

6 0
3 years ago
What is the measurement of this square?<br> A.075<br> B. 1.75<br> C. 0.34
Katena32 [7]

Answer:

0.75 in

Explanation:

The 1 inch measure has 16 divisions.

Find the measure of 1 division as: 1/16 = 0.0625 in

The side length of the square has 12 divisions

1 division = 0.0625 in

12 divisions = 0.0625*12 = 0.75 in

The correct answer choice is A. 0.75.

Answer choices B is incorrect because from the diagram, it is clear that the side length of this square is less that 1 inch.

Answer choice C is incorrect because 0.34 in will mean 0.34/0.0625 divisions. This is 5 divisions, yet the square side length covers 12 divisions.

7 0
3 years ago
Why is a metal work enclosure dangerous?
dedylja [7]

Answer:

Why is a metal work enclosure dangerous? Metalworkers are not only exposed to pollutants from metal cut ting and polishing procedures, but they are also exposed to metalworking fluids (MWF).

8 0
2 years ago
A controller for a satellite attitude control with transfer function G = 1 s 2 has been designed with a unity feedback structure
S_A_V [24]

Answer:

type 2, k = 4

Explanation:

(a) The transfer function of the controller for a satellite attitude control is  

G = \frac{1}{s^2}

The transfer function of unity feedback structure is

D(s) = \frac{10(s+2)}{s+5}  

To determine system type for reference tracking, identify the number of poles at origin in the open-loop transfer function.  

For unity feedback system, the open-bop transfer function

G(s)D_c(s)=\frac{1}{s^2}\frac{10(s+2)}{s+5}

                =\frac{10(s+2)}{s^2(s+5)}

Determine the poles in G(s)4(s).

s = 0,0,-5

Type of he system is decided by the number of poles at origin in the open loop transfer function.

Since, there are two poles at origin, the type of the system will be 2.  

Therefore, the system type is  

Type 2  

check the attached file for the concluding part of the solution

5 0
3 years ago
Other questions:
  • What must you do if hauling a load of material which could fall or blow onto the roadway?
    14·1 answer
  • The minimum safe working distance from exposed electrical conductors
    13·1 answer
  • A new 1.2-ha suburban residential development is to be drained by a storm sewer that connects to the municipal drainage system.
    15·1 answer
  • Express the unsteady angular momentum equation in vector form for a control volume that has a constant moment of inertia I, no e
    9·1 answer
  • Digital leaders are people who __ others down a particular path.
    13·2 answers
  • How do I get my son to do his work?
    6·1 answer
  • What are the laws that apply to one vehicle towing another?
    11·1 answer
  • Which of the following was a sustainable power source used during the Middle Ages?
    9·2 answers
  • Where would the impossible amount of product 1 and 2 points intersect on the production possibility curve
    6·1 answer
  • Define waves as it applies to electromagnetic fields
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!