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
Several different loads are going to be used with the voltage divider from Part A. If the load resistances are 300 kΩkΩ , 200 kΩ
harina [27]

Answer:

attached below

Explanation:

7 0
3 years ago
A negative pressure respirator brings fresh air to you through a hose<br>A) True<br>B)False​
madreJ [45]

Answer:FALSE

Explanation: A negative pressure respirator is a respiratory system which is known to have a low air pressure inside the mask when compared to the air pressure on the outside during Inhalation.

Most of the personal protective equipment (PPE) which are in use in various industries are examples of Negative pressure respirator device,any leak or damage done to the device will allow the inflows of harmful and toxic Air into the person's respiratory system. AIR SUPPLY SYSTEMS ARE KNOWN TO SUPPLY FRESH UNCONTAMINATED AIR THROUGH AIR STORED INSIDE COMPRESSED CYLINDERS OR OTHER SOURCES AVAILABLE.

8 0
3 years ago
Read 2 more answers
جائت فكرة ربط الحواسيب لغرض نقل البيانات و مشاركتها و بعدها بفتره قصيره جائت إمكانية مشاركة الموارد بين الحواسيب صح ام خطأ​
melamori03 [73]

Answer:

بدلاً من ذلك يُشار إليه باسم مشاركة أو مشاركة شبكة ، الدليل المشترك هو دليل أو مجلد يمكن الوصول إليه من قبل العديد من المستخدمين على الشبكة. هذه هي الطريقة الأكثر شيوعًا للوصول إلى المعلومات ومشاركتها على شبكة محلية

Explanation:

5 0
3 years ago
Read 2 more answers
- WHEN YOU ARE TOWING A TRAILER:
zheka24 [161]

Answer:

And Im still going with B..

7 0
3 years ago
Paragraph summary on airplane history
irga5000 [103]

Answer:The Wright brothers invented and flew the first airplane in 1903, recognized as "the first sustained and controlled heavier-than-air powered flight". ... Airplanes had a presence in all the major battles of World War II. The first jet aircraft was the German Heinkel He 178 in 1939.

Explanation:

4 0
3 years ago
Other questions:
  • In what situation you would prefer to use a successive approximation ADC over flash ADC?
    13·1 answer
  • Determine displacement (in) of a 1.37 in diameter steel bar, which is 50 ft long under a force of 27,865 lb if elasticity modulu
    5·1 answer
  • Technician A says if the input signal turn-on time is too fast for the input circuit, your program may operate as though the inp
    11·1 answer
  • All of these are true about GMA (MIG) welding EXCEPT that:
    12·1 answer
  • Vector A extends from the origin to a point having polar coordinates (7, 70ᵒ ) and vector B extends from the origin to a point h
    9·1 answer
  • Work to be performed can come from the work package level of the work breakdown structure as well as other sources. Which of the
    11·1 answer
  • What is the purpose for this experiment
    9·1 answer
  • QUESTION ONE Write short answers on the following questions: i. Rainfall depth over a watershed is monitored through six number
    15·1 answer
  • What is the placement of a lock out device on an energy isolating device?.
    12·1 answer
  • 11. What are restrictions when building or completing a challenge?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!