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
Please what is the name of this tool​
madam [21]

Answer: it’s called a saw or see saw

Explanation: it works by cutting a tree, wood, tile, etc.

5 0
3 years ago
Read 2 more answers
The E7018 Electrode produces a/an
julia-pushkina [17]

Answer:

Explanation:

These include the 6010, 6011, 6012, 6013, 7014, 7024 and 7018 electrodes. 6010 electrodes deliver deep penetration and have the ability to “dig” through rust, oil, paint or dirt, making them popular among pipe welders.

7 0
3 years ago
JAVA HADOOP MAPREDUCE
taurus [48]

Answer:

Explanation:

package PackageDemo;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;

import org.apache.hadoop.fs.Path;

import org.apache.hadoop.io.IntWritable;

import org.apache.hadoop.io.LongWritable;

import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Job;

import org.apache.hadoop.mapreduce.Mapper;

import org.apache.hadoop.mapreduce.Reducer;

import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;

import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import org.apache.hadoop.util.GenericOptionsParser;

public class WordCount {

public static void main(String [] args) throws Exception

{

Configuration c=new Configuration();

String[] files=new GenericOptionsParser(c,args).getRemainingArgs();

Path input=new Path(files[0]);

Path output=new Path(files[1]);

Job j=new Job(c,"wordcount");

j.setJarByClass(WordCount.class);

j.setMapperClass(MapForWordCount.class);

j.setReducerClass(ReduceForWordCount.class);

j.setOutputKeyClass(Text.class);

j.setOutputValueClass(IntWritable.class);

FileInputFormat.addInputPath(j, input);

FileOutputFormat.setOutputPath(j, output);

System.exit(j.waitForCompletion(true)?0:1);

}

public static class MapForWordCount extends Mapper<LongWritable, Text, Text, IntWritable>{

public void map(LongWritable key, Text value, Context con) throws IOException, InterruptedException

{

String line = value.toString();

String[] words=line.split(",");

for(String word: words )

{

Text outputKey = new Text(word.toUpperCase().trim());

IntWritable outputValue = new IntWritable(1);

con.write(outputKey, outputValue);

}

}

}

public static class ReduceForWordCount extends Reducer<Text, IntWritable, Text, IntWritable>

{

public void reduce(Text word, Iterable<IntWritable> values, Context con) throws IOException, InterruptedException

{

int sum = 0;

for(IntWritable value : values)

{

sum += value.get();

}

con.write(word, new IntWritable(sum));

}

}

}

3 0
2 years ago
The period of a pendulum T is assumed to depend only on the mass m, the length of the pendulum `, the acceleration due to gravit
zzz [600]

Answer:

The expression is shown in the explanation below:

Explanation:

Thinking process:

Let the time period of a simple pendulum be given by the expression:

T = \pi \sqrt{\frac{l}{g} }

Let the fundamental units be mass= M, time = t, length = L

Then the equation will be in the form

T = M^{a}l^{b}g^{c}

T = KM^{a}l^{b}g^{c}

where k is the constant of proportionality.

Now putting the dimensional formula:

T = KM^{a}L^{b}  [LT^{-} ^{2}]^{c}

M^{0}L^{0}T^{1} = KM^{a}L^{b+c}

Equating the powers gives:

a = 0

b + c = 0

2c = 1, c = -1/2

b = 1/2

so;

a = 0 , b = 1/2 , c = -1/2

Therefore:

T = KM^{0}l^{\frac{1}{2} } g^{\frac{1}{2} }

T = 2\pi \sqrt{\frac{l}{g} }

where k = 2\pi

8 0
3 years ago
What is the measurement below?
Bess [88]

Explanation:

इसिसिसिसैस्स्स्स्स्स्स्स्स्स्सूस्सोस्स्स्स्स्स

8 0
2 years ago
Other questions:
  • Zona intermedia de pozos <br> Y<br> Efecto de inavasion
    6·1 answer
  • . A roadway is being designed capable of allowing 70 mph vehicle speed. The superelevation around one curve is 0.05 inches per i
    15·1 answer
  • A rod of length L lies along the x axis with its left end at the origin. It has a nonuniform charge density λ = αx, where α is a
    14·2 answers
  • Can you carry 1 m3 of liquid water? Why or why not? (provide the weight to support your answer)
    7·1 answer
  • Find values of the intrinsic carrier concentration n for silicon at –70° 0° 20° C, 100° C, and C. At 125° each temperature, what
    14·1 answer
  • A city emergency management agency and a construction company have formed a public-private partnership. The construction company
    15·1 answer
  • Match the use of the magnetic field to its respective description.​
    6·1 answer
  • A helicopter is hovering in a steady cross wind at a gross weight of 3,000 lb (1,360.8 kg). This helicopter has 275 hp (205 kW)
    10·1 answer
  • Outline how effective brainstorming should be set up so that it does not go off-track or alienate anyone.
    15·1 answer
  • What color is a board sternlight
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!