Home / Expert Answers / Computer Science / 3-16-zylab-refactoring-calculating-fuel-cost-i-don-39-t-know-why-this-question-is-not-letting-me-g-pa432

(Solved): 3.16 ** zyLab: Refactoring Calculating Fuel Cost I don't know why this question is not letting me g ...



3.16 ** zyLab: Refactoring Calculating Fuel Cost

I don't know why this question is not letting me get the full marks. I think I kept all the requirements for the assignment but I wonder which part of my code that I have a problem with, displaying that it could not find any three constant double variables.

This lab section is focusing on implementing and calling methods.
In programming, the term refactoring means to review and re

3.16.1: ** zyLab: Refactoring Calculating Fuel Cost
25
CostEstimator.java
import java.util.Scanner;
import java.lang.Math;
pu

Latest submission - 11:03 PM CST on 02/19/23
Total score: \( 25 / 30 \)
Only show failing tests
1:Constant check \( \boldsymb

This lab section is focusing on implementing and calling methods. In programming, the term refactoring means to review and re-write your code to improve its quality. That is, code refactoring improves the quality of the code, but it doesn't change its functionality. Copyyyour code from the zyLab: Calculate Fuel Cost, and refactor it to use the following four methods. Note that only the calculations are done in the individual methods (as can be seen by the return type of the methods). All print statements should be in the main method still. DO NOT CHANGE THE METHOD HEADERS! 3.16.1: ** zyLab: Refactoring Calculating Fuel Cost 25 CostEstimator.java import java.util.Scanner; import java.lang.Math; public class CostEstimator \{ * Calculates the amount of fuel needed. * @param distance The distance of the trip. * @param milesPerLiter Total distance that could be achieved with 1 liter of fuel. * @return Total fuel needed. */ public static double calcFuelNeeded(double distance, final double milesPerLiter) \{ return distance / milesPerLiter; \} * Calculates the total number of gallons needed. * @param fuelNeeded Total fuel needed. * @param litersPerGallon The volume of each gallon. * @return Total number of gallons needed. */ public static int calcGallonsFuelNeeded(double fuelNeeded, final double litersPerGallon) \{ return (int) Math.ceil((fuelNeeded / litersPerGallon)); \} * Calculates the total cost needed. * @param gallonsFuel Total number of gallons needed. * @param costPerGallon The cost of each gallon. * @return The total cost of the trip. */ public static double calcCostNeeded(int gallonsFuel, final double costPerGallon) \{ return gallonsFuel * costPerGallon; \} public static void main(String[] args) \{ Scanner scnr = new Scanner(System.in); System.out.println("Enter the distance to be covered (miles):"); double distance scnr . nextDouble(); final double milesPerLiter ; double fuelNeeded = calcFuelNeeded(distance, milesPerLiter); final double litersPerGallon ; int gallonsFuel = calcGallonsFuelNeeded(fuelNeeded, litersPerGallon); final double costPerGallon ; double totalCost calcCostNeeded(gallonsFuel, costPerGallon); System.out.println("Fuel Needed: " + fuelNeeded + " liter(s)"); System.out.println("Gallons needed: " + gallonsFuel + " gallon(s)"); System. out.println("Cost needed: " + totalCost + " \$"); \} Latest submission - 11:03 PM CST on 02/19/23 Total score: Only show failing tests 1:Constant check Checks for constant variables. \begin{tabular}{l|l} Test feedback & Three constant double variables expected. Only found 0. \\ If you have three, are they named correctly? Do they have the correct va \end{tabular} 2:Compare output Input \begin{tabular}{l|l} Ynter the distance to be covered (miles): \\ Your output & Fuel Needed: liter(s) \\ Gallons needed: 2 gallon(s) \\ Cost needed: \end{tabular} 3:Compare output Input \begin{tabular}{l|l} Your output & Enter the distance to be covered (miles): \\ Fuel Needed: liter(s) \\ Gallons needed: 20 gallon(s) \\ Cost needed: \end{tabular} 4:calcFuelNeeded unit test Test calcFuelNeeded 5:calcGallonsFuelNeeded unit test Test calcGallonsFuelNeeded


We have an Answer from Expert

View Expert Answer

Expert Answer


We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe