Answer:
import java.util.Scanner;
public class ANot {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("Please Enter the number of fuel gallons in the car's tank: ");
int numGallons = input.nextInt();
System.out.print("What is the fuel efficiency of your car in miles/gallon ");
double fuelEffi = input.nextDouble();
System.out.print("How much is the price per gallon: ");
double price = input.nextDouble();
double milesCanGo = fuelEffi*numGallons;
double numOfGallons100Miles = 100/fuelEffi;
System.out.println("The cost per 100 miles is "+numOfGallons100Miles*price);
System.out.println("Your car can go as far as "+milesCanGo+" miles with the current fuel " +
"in your tank");
}
}
Explanation:
Using Java programming language;
- Import the Scanner class to receive user input
- Prompt user to input numofGallons, fuelEfficiency and pricePerGallon
- Calculate the miles the car can go with the formula milesCanGo = numofGallons X fuelEfficiency
- Calculate the number of gallons for 100 miles distance (100/fuelEfficiency)
- The cost of driving 100 miles is (100/fuelEfficiency)*pricePerGallon
- Output cost for 100 miles and how far the car can go.