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]
2 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]2 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
2.14 (a) Using series/parallel resistance reductions, find the equivalent resistance between terminals A and B in the circuit of
olasank [31]

Answer:

There is no attachment

5 0
2 years ago
Solid Isomorphous alloys strength
Sphinxa [80]

Answer:

Explanation:

ℎ

3 0
3 years ago
List and describe three classifications of burns to the body.
DiKsa [7]

AnswerWhat Are the Classifications of Burns? Burns are classified as first-, second-, or third-degree, depending on how deep and severe they penetrate the skin's surface. First-degree burns affect only the epidermis, or outer layer of skin. The burn site is red, painful, dry, and with no blisters.

Explanation:

8 0
3 years ago
Read 2 more answers
List all the qualities of an engineer?
Dennis_Churaev [7]

Answer:

Math and Computer Skills. A qualified engineer should be good at math, at least through the level of calculus and trigonometry, and understand the importance of following the data when making design decisions.

Organization and Attention to Detail.  

Curiosity.  

Creativity.  

Critical Thinking.

Intuition.

Explanation:

6 0
2 years ago
Tahir travel twice as far as ahmed, but onley one third as fast. Ahmed starts travel on tuesday at noon at point x to point z 30
shepuryov [24]

Answer:

6:00 pm the next day

Explanation:

Given that

Tahir traveled twice as far as Ahmed. We say,

Ahmed traveled a distance, D

Tahir would travel a distan, 2D

Tahir traveled 1/3 as fast as Ahmed, so we say

Ahmed traveled at a speed, S

Tahir would travel at a speed, S/3

If Ahmed starts travel on tuesday at noon at point x to point z 300km, by 9:00pm,

Time taken by Ahmed to travel is

9:00 pm - 12:00 pm = 9 hours

Ahmed, traveled 300 km in 9 hours, meaning he traveled at 33.3 km in an hour.

Speed, S that Ahmed traveled with is 33.3 km/h

Remember, we stated that Tahir travels at a speed of S/3, that is, The speed of Tahir is

33.3/3 = 11.1 km/h.

300 km would then be traveled in 300 km/11.1 km/h = 27 hours.

Tahir started traveling, 3 hours after Ahmed, that is 12:00 pm + 3:00 hrs = 3:00 pm, and if he's to spend 27 hours on the journey he would reach destination z at 6:00 pm the next day

7 0
2 years ago
Other questions:
  • To prevent hydroplaning, _____. A. slow down B. speed up C. deflate your tires D. use cruise control
    15·1 answer
  • A mass of 8000 kg of slightly enriched uranium (2% U-235, 98% U-238) is exposed for 30 days in a reactor operating at (6.18) hea
    5·1 answer
  • If 20 kg of iron, initially at 12 °C, is added to 30 kg of water, initially at 90 °C, what would be the final temperature of the
    6·1 answer
  • Polymer ropes and lines for use on water are often designed to float, to aid in their retrieval and to avoid applying a downward
    6·1 answer
  • Is air conditioner a refrigerator?
    10·1 answer
  • What are four engineering degrees that can help lead you to becoming an aerospace engineer
    6·1 answer
  • 1. How does manufacturing help strengthen<br> the economy?
    15·1 answer
  • What is the uncertainty in position of an electron of an atom if there is t 2.0 x 10' msec uncertainty in its velocity? Use the
    12·1 answer
  • A force measuring instrument comes with a certificate of calibration that identifies two instrument errors and assigns each an u
    12·1 answer
  • Please help been stuck on this for a couple minutes
    5·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!