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
3–102 One of the common procedures in fitness programs is to determine the fat-to-muscle ratio of the body. This is based on the
gayaneshka [121]

Answer:

x_fat = [ 0.5*(Wsa + Wsw) -  p_muscle*V ] / V*( p_fat - p_muscle )

Explanation:

Given:

- The total volume of body = V

- The average density of the body = p_avg

- The density of muscle = p_muscle

- The density of fat = p_fat

Find:

Obtain a relation for the volume fraction of body fat x_fat

Solution:

- The volume of the fat is given by:

                          V_fat = x_fat*V

- The volume of the muscle is given by:

                          V_muscle = V - V_fat

                                            = V - x_fat*V

                                            =V*( 1 - x_fat )

- We will use the conservation of mass for the body related as:

                         mass_fat + mass_muscle = Total average mass

                         p_fat*V_fat + p_muscle*V_muscle = p_avg*V

                         p_fat*x_fat*V + p_muscle*V*( 1 - x_fat ) = p_avg*V

                         p_fat*x_fat + p_muscle*( 1 - x_fat ) = p_avg

- To determine p_1 we weigh the body in air:

                         Weight reading (Wsa) = m = p_1*V

                         p_1 = Wsa / V*g

- To determine p_2 we weigh the body in water:

                         Weight reading (Wsw) = m - p_w*V= p_1*V - p_w*V

                         Weight reading (Wsw) = V*(p_1 - p_w) = V*(p_2)

                         Where, p_2 = p_1 - p_water

                         p_2 = Wsw / V

- The average density p_avg:

                         p_avg = 0.5*(p_1 + p_2)  

                         p_avg = 0.5*(Wsa / V + Wsw / V)  

                         p_avg = 0.5*(Wsa + Wsw) / V                      

- Plug in the mass equation:

                         p_fat*x_fat + p_muscle*( 1 - x_fat ) = 0.5*(Wsa + Wsw) / V

                         x_fat*( p_fat - p_muscle ) = 0.5*(Wsa + Wsw) / V - p_muscle

                   x_fat = [ 0.5*(Wsa + Wsw) -  p_muscle*V ] / V*( p_fat - p_muscle )

                         

6 0
4 years ago
A centrifugal pump is required to pump water to an open water link situated 4 km away from the location of the pump through a pi
11111nata11111 [884]

Answer:

P= 5.5 bar

Explanation:

Given that

L= 4000 m

d= 0.2 m

Friction factor(F) = 0.01

speed V= 2 m/s

Head = 5 m

Head loss due to friction

h_f=\dfrac{FLV^2}{2gd}

h_f=\dfrac{0.01\times 4000\times 2^2}{2\times 9.81\times 0.2}

h_f=40.77m

So the total head(H) = 5 + 40.77 + 10.3 =56.07

Where 10.3 m is the atmospheric head.

We know that

P=ρ g H

So total Pressure

P= 1000 x 9.81 x 56.07 Pa

P=5.5\times 10^5\ Pa

P= 5.5 bar

5 0
4 years ago
Which of the following correctly describes caster?
sertanlavr [38]
Lil durk 4000
Example

3 0
3 years ago
Describe the algorithm you use for looking up a person’s telephone number in the phone book. The input is person’s name; the out
Stella [2.4K]

Answer:

The Algorithm for finding a number from a phone book with the person's name as the input and the phone number as output is as follows:

1. Try to remember the name, i.e last name first and first name last, Also make sure you get the spelling right.

2. Using the first letter of the last name, locate the appropriate alphabetical section in which the name should appear.

3. Using the second letter of the last name, find the subsection of first and second letters combined, in the appropriate order, in which the name should appear. (If the last name consists of only two letters, find the appropriate first name.)

4. Using the third letter, find the possible names in a subsection of the first three letters in the correct order. Continue this step with x+1 letters of the name until you have a subsection of names exactly matching the last name of the person whose number you are trying to locate. (x is the number of letters used in the previous step, consistently.) If there is only one of the last name, (check for duplicates) identify the number, and return phone number information.

5. Begin the second step using the first letter of the first name, but limit the section to only those exactly matching the last name. Continue to step 4, again focusing on the first name only within the set of exactly matching last names.

6. When both first and last name match the name you are locating, check for duplicates. IF there are no duplicates, return phone number information.

Explanation:

People's names are generally arranged in phone books in alphabetical order by the last name of the person. The first name of the person is listed after the last name so that people of the same last name can be differentiated.

7 0
4 years ago
Read 2 more answers
What can your employer do to protect you from overhead power lines?
agasfer [191]

Answer:

Have the power company install insulated sleeves (also known as “eels”) over power lines.​

Wearing PPE is the only way to prevent being electrocuted

Explanation:

To prevent electrocution at workplace, employers can ensure that the  power company install insulated sleeves (also known as “eels”) over power lines.​ Additionally, the employees should wear PPEs which are insulators to prevent electrocution.

5 0
3 years ago
Other questions:
  • What is the stress concentration factor of a shaft in torsion, where D=1.25 in. and d=1 in. and the fillet radius is, r=0.2 in.a
    7·1 answer
  • A seawall with an opening is used to dampen the tidal influence in a coastal area (and limit erosion). The seawall is 2.5 m long
    11·1 answer
  • You will be observing laminar-turbulent transition for room temperature (about 20°C) water flowing in a 0.602"" ID pipe (Schedul
    8·1 answer
  • You are using a Geiger counter to measure the activity of a radioactive substance over the course of several minutes. If the rea
    8·1 answer
  • Estimate the uncertainty in a 22 m/sec air velocity measurement using a Pitot tube at 20C. Assume the atmospheric pressure is 1
    7·1 answer
  • Is a unit of measurement for angles
    15·1 answer
  • The purpose of the international residential code is to
    9·1 answer
  • Select the correct answer. The most frequent maintenance task for a car is: A. Oil changes B. Tire replacements C. Coolant chang
    10·2 answers
  • A golfer and her caddy see lightning nearby. the golfer is about to take his shot with a metal club, while her caddy is holding
    12·1 answer
  • What do u mean by double entry bookkeeping system?<br>u fellas don't spam pls​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!