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. Round off 2553 N to three significant figures.
Marizza181 [45]

Answer:

(1) 2553 N = 2550 N

(2) 58342 m = 58300 m

(3) 68.534 s = 68.5 s

Explanation:

To round off a number to any significant number start from the last digit, round it off to 1 if the number is up to 5 and to 0 if the last digit is less than 5. Add this 1 or 0 to the preceding digit and continue the process until you are left with three non zero digits, if you are rounding off to three significant figures.

(1) Round off 2553 N to three significant figures.

= 2550 N

(2) Round off 58342 m to three significant figures.

= 58300 m

(3) Round off 68.534 s to three significant figures.

= 68.500 s (zero after decimal point is insignificant)

= 68.5 s

8 0
4 years ago
3.8. Describe the two alternatives for specifying structural constraints on relationship types. What are the advantages and disa
forsale [732]

Answer: CARDINALITY RATIO AND PARTICIPATION

ADVANTAGE

CARDINALITY RATIO

(THEY ARE USED TO SIMPLIFY DESIGNS)

DISADVANTAGE OF CARDINALITY RATIO IS THAT

(YOU CAN NOT SPECIFY A GIVEN NUMBER TO BE MAXIMUM)

ADVANTAGE OF PARTICIPATION CONSTRAINT IS THAT

(IT SHOWS WETHER THE EXISTENCE OF AN ENTITY IS DEPENDENT ON ITS RELATIONSHIPS WITH ANOTHER ENTITY)

DISADVANTAGE OF PARTICIPATION CONSTRAINT

(IT IS A COSTLY AFFAIR USING BOTH MODELS TO EXPRESEE RELATIONSHIPS).

Explanation:CARDINALITY RATIO specifies that maximum number of relationships an entity can engage itself in.

Participation constraint is a constraint that

Specifies whether the existence of an entity depends on its Relationships to another entity, it specifies the the minimum number of relationship instances that an entity can participate in

It is also minimum cardinality constraint,it has two types named as Total participation and partial participation.

7 0
4 years ago
Hãy trình bày sự hiểu biết của bạn về đo dòng điện
Sidana [21]

Answer:

-Khái niệm:

Đo dòng điện là sử dụng các dụng cụ như ôm kê, vôn kế, ampe kế, tần số kế… để xác định các đại lượng vật lý của dòng điện

-Đo lường điện để làm gì?

Phát hiện hư hỏng sự cố trong mạch điện và các thiết bị vi mạch

Xác định các giá trị cần đo

Đánh giá chất lượng của các thiết bị sau sản xuất

Xác định thông số kỹ thuật của thiết bị

-Phân loại dụng cụ đo điện: Hiên nay có 2 phương pháp phân loại chính

a. Theo nguyên lý làm việc

Dụng cụ đo kiểu điện từ

Dụng cụ đo kiểu điện động

Dụng cụ đo kiểu cảm ứng

Dụng cụ đo kiểu từ điện

b. Theo đai lượng, giá trị cần đo

+Đo điện năng: Ví dụ công tơ điện

+Đo điện áp: Ví dụ: Vôn kế

+Đo dòng điện: Ví dụ: Ampe kế

+Đo công suất: Oát kế

+Đo điện trở: Ôm kế

Sai số khi đo: Khi đo lường luôn xảy ra các sai số

Sai số tương đối: Là tỷ lệ % của sự chênh lệch giữa giá trị đo được và giá trị thự

8 0
3 years ago
The velocity distribution for laminar flow between parallel plates is given by u umax = 1 − ( 2y h ) 2 Where h is the distance s
Lynna [10]

Answer:

Explanation:

For we to calculate the shear stress on the upper plate and give its direction. Sketch the variation of shear stress across the channel, I used hand in solving it, check attached file below

5 0
4 years ago
Why are there few effective HCI standards?
Oliga [24]

Answer:

<em>There are few effective Human Computer Interaction (HCI) standards because for one, standards are more suitable for hardware than software because they are relatively unstable. ... Some software product standards have been in place long before any formal standard documents were published.</em>

3 0
3 years ago
Other questions:
  • The volume at a section of a 2-lane highway is 1800 vph in each direction and the density is approximately 30 bpm. A slow moving
    10·1 answer
  • 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
  • A spherical, stainless steel (k 16 W m1 K-1) tank has a wall thickness of 0.2 cm and an inside diameter of 10 cm. The inside sur
    12·1 answer
  • Air at 80 kPa and 10°C enters an adiabatic diffuser steadily with a velocity of 150 m/s and leaves with a low velocity at a pre
    11·1 answer
  • Plz fill these gaps.<br>thank u so much.<br>​
    11·1 answer
  • Brainly and points if you want
    13·2 answers
  • La osteoporosis puede presentarse en la epoca de el embaraso y la lactancia
    9·1 answer
  • Tech A says that the standard 12-volt car battery has 3 cells with 4.2 volts in each cell. Tech B says that the
    15·1 answer
  • Is the science of measurement
    6·1 answer
  • Would anyone be able to tell me what this is? it's for a water pump​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!