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
1. If a Gear with a 3 inch Diameter is being turned by a Gear with a 6 inch Diameter, which Gear will rotate at a higher Rate?
pshichka [43]

Answer:

The smaller gear will rotate faster.

Explanation:

If a larger gear is driven by a smaller gear, the large gear will rotate slower than the smaller gear but will have a greater moment. For example, a low gear on a bike or car. If a smaller gear is driven by a larger gear, the smaller gear will rotate quicker than the larger gear but will have a smaller moment.

I hope this helps! :)

5 0
2 years ago
Write a statement that calls the recursive method backwardsAlphabet() with parameter startingLetter.
Tcecarenko [31]

Recursion refers to the act of calling a function itself. With the use of this strategy, complex problems can be reduced to more manageable, simpler ones. Recursion might be a little challenging to comprehend. The best method to figure out how it works is to experiment with it.

<h3>How to write a programme by recursive method ?</h3>

The process of making a function call itself is known as recursion. With the use of this strategy, complex problems can be reduced to more manageable, simpler ones. Recursion might be a little challenging to comprehend. Experimenting with it is the most effective way to learn how it functions.

public class Recursive Calls {

public static void backwards Alphabet(char currLetter) {

if (currLetter == 'a') {

System.out.println(currLetter);

}

else {

System.out.print(currLetter + " ");

backwards Alphabet(--currLetter);

}

return;

}

public static void main (String [] args) {

char starting Letter = '-';

starting Letter = 'z';

// Your solution goes here

backwards Alphabet(starting Letter);

return;

}

}

To learn more about recursive method refer to :

brainly.com/question/24167967

#SPJ4

6 0
1 year ago
A(n) _____________ is used commonly in open split-phase motors to disconnect the start winding from the electrical circuit when
Alenkasestr [34]

A <u>centrifugal switch</u> is used commonly in open split-phase motors to disconnect the start winding from the electrical circuit when the motor reaches approximately 75% of its rated speed.

Hope that helps!

7 0
2 years ago
A light bulb is switched on and within a few minutes its temperature becomes constant. Is it at equilibrium or steady state.
EleoNora [17]

Answer:

The temperature attains equilibrium with the surroundings.  

Explanation:

When the light bulb is lighted we know that it's temperature will go on increasing as the filament of the bulb has to  constantly dissipates energy during the time in which it is on. Now this energy is dissipated as heat as we know it, this heat energy is absorbed by the material of the bulb which is usually made up of glass, increasing it's temperature. Now we know that any object with temperature above absolute zero has to dissipate energy in form of radiations.

Thus we conclude that the bulb absorbs as well as dissipates it's absorbed thermal energy. we know that this rate is dependent on the temperature of the bulb thus it the temperature of the bulb does not change we can infer that an equilibrium has been reached in the above 2 processes i.e the rate of energy absorption equals the rate of energy dissipation.

Steady state is the condition when the condition does not change with time no matter whatever the surrounding conditions are.

6 0
3 years ago
Name some technical skills that are suitable for school leavers .​
Natalka [10]

Answer:

Welding, carpentry, masonry, construction worker, barber

Explanation:

7 0
3 years ago
Other questions:
  • A minor road intersects a major 4-lane divided road with a design speed of 55mph and a median width of 8 feet. The intersection
    11·1 answer
  • Suppose you are implementing a relational employee database, where the database is a list of tuples formed by the names, the pho
    14·1 answer
  • Hey, can anyone tell me if Igneous rock is good to build on? Cheers!
    6·1 answer
  • Pennfoster Trades Safety test. Would appreciate the help. Thank you in advance. Check the screenshots below for the questions I'
    8·1 answer
  • A Water Amusement Park parking lot charges $24.00 minimum fee to park for up to 8 hours. The meter charges an additional $3.25 p
    5·2 answers
  • Design an Armstrong indirect FM modulator to generate an FM signal with a carrier frequency 98.1 MHz and a frequency deviation △
    15·1 answer
  • Consider a metal single crystal oriented such that the normal to the slip plane and the slip direction are at angles of 43.1 deg
    6·1 answer
  • BIG POINTS AND WILL GIVE BRAINLIEST! Answer all 5 please or I can’t give brainliest and might report!
    10·1 answer
  • Why are Gas cars Bad?(cons) give me reasons why gasoline cars are bad<br><br>Thx if u help ​
    14·1 answer
  • Some wire of radius is 1.262mm has a resistance of 20Ω. Determine the resistance of a wire of the same length and material if th
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!