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 of the following is NOT an ASE certification? Select one:
stiks02 [169]

The option that is not an ASE certification is . A/C and Refrigerants handling certification (609).

<h3>What is ASE certification?</h3>

The term ASE is known to be a body that tends to promotes excellence in regards to vehicle repair, service as well as parts distribution.

Note that in the world today more than a quarter of  million of people are known to possess ASE certifications.

Since ASE Certified professionals work in in all areas of the transportation industry. one can say that The option that is not an ASE certification is. A/C and Refrigerants handling certification (609).

Learn more about ASE certification from

brainly.com/question/5533417

#SPJ1

8 0
2 years ago
Please view the file attached below and help me answer all the questions!!
evablogger [386]

Answe whats the question i can help you

Explanation:

8 0
3 years ago
Sed is a multipurpose tool that combines the work of several filters. sed performs noninteractive operations on a data stream. s
timama [110]

Answer:

The answer is True.

Explanation:

SED is a command in UNIX for stream editors that parses and transforms text, using a simple, compact programming language. So the answer is TRUE that sed is a multipurpose tool that combines the work of several filters and performs noninteractive operations on a data stream. sed has a host of features that allow you ti select lines and run instructions on them.

6 0
3 years ago
What is equation for surface area?
Marysya12 [62]

Answer:

Surface area is the sum of the areas of all faces (or surfaces) on a 3D shape. pls mark me branilest

6 0
3 years ago
A 10.2 mm diameter steel circular rod is subjected to a tensile load that reduces its cross- sectional area to 52.7 mm^2. Determ
VMariaS [17]

Answer:

The percentage ductility is 35.5%.

Explanation:

Ductility is the ability of being deform under applied load. Ductility can measure by percentage elongation and percentage reduction in area. Here, percentage reduction in area method is taken to measure the ductility.

Step1

Given:

Diameter of shaft is 10.2 mm.

Final area of the shaft is 52.7 mm².

Calculation:

Step2

Initial area is calculated as follows:

A=\frac{\pi d^{2}}{4}

A=\frac{\pi\times(10.2)^{2}}{4}

A = 81.713 mm².

Step3

Percentage ductility is calculated as follows:

D=\frac{A_{i}-A_{f}}{A_{i}}\times100

D=\frac{81.713-52.7}{81.713}\times100

D = 35.5%.

Thus, the percentage ductility is 35.5%.

5 0
3 years ago
Other questions:
  • In the formula shown, k is a correction factor for nonideal mixing. In the worst case, k is usually estimated to be:_______. Cpp
    8·1 answer
  • When should you exercise extreme caution around power lines?
    6·1 answer
  • You need to sort a file of n GB file stored on a hard-drive. Your RAM contains only 5GB. You have a lightning-fast CPU, but writ
    13·1 answer
  • As the temperature of a thermal radiator is increased Group of answer choices the object appears redder. the object appears blue
    7·1 answer
  • Why are open systems harder to study than closed systems?​
    6·1 answer
  • If the dry-bulb temperature is 95°F and the wet-bulb temperature is also 78°F, what is the relative humid- ity? What is the dew
    5·1 answer
  • What is the definition of a tolerance on a dimension typically found on technical drawings?
    7·1 answer
  • Is the science of measurement
    6·1 answer
  • In a CS amplifier, the resistance of the signal source Rsig = 100 kQ, amplifier input resistance (which is due to the biasing ne
    11·1 answer
  • Explain Flags in ARM Processor​
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!