Question
import java.util.Scanner; import java.lang.Math; public class CostEstimator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double distance = 0.0; double fuelNeeded
import java.util.Scanner; import java.lang.Math;
public class CostEstimator { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); double distance = 0.0; double fuelNeeded = 0.0; int gallonsFuel = 0; double costNeeded = 0.0;
final double MILES_PER_LITER = 13.7; final double LITER_PER_GALLON = 3.785; final double COST_PER_GALLON = 2.629; System.out.println("Enter the distance to be covered (miles):"); distance = scnr.nextDouble();
fuelNeeded = 0.0; // FIXME (1): Calculate the fuel needed System.out.println("Fuel Needed: "); fuelNeeded = scnr.nextDouble();
// FIXME (2): Calculate and output the amount of gallons needed for the trip // FIXME (3): Calculate and output the total cost needed for the trip
} }
As with the previous labs, use Diff Checker to compare your programs output to that of the examples before submitting to zyBooks for grading (1) Prompt the user to input the distance to be covered by a vehicle. The values should be doubles. Calculate the total amount of fuel needed as a double. Assume that fuel efficiency is 13.7 miles/liter. Store this value using a constant double variable called MILES_PER_LITER (2 pts) Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs. Enter the distance to be covered (miles): 66 Fuel Needed: 4.817518248175182 liter (s) (2) Extend to also calculate and output the amount of fuel in gallons needed to cover the distance (as an integer). Assume a gallon contains 3.785 liters fuel. Store this value using a constant double variable called LITER_PER_GALLON. Hint: For the calculation, use the round method in the Math class to round up the number of gallons. (2 pts) Enter the distance to be covered (miles): 66 Fuel Needed: 4.817518248175182 liter(s) Gallons needed: 2 gallon (s) (3) Extend to also calculate and output the cost needed for the trip. Assume a gallon worth 2.629 $. Store it using a constant double variable called COST_PER_GALLON. (2 pts) Enter the distance to be covered (miles): 66 Fuel Needed: 4.817518248175182 liter(s) Gallons needed: 2 gallon(s) Cost needed: 5.258 $Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started