Question: 2.21 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas


2.21 LAB: Driving costs Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows: System.out.printf("%.2f", yourValue); The output ends with a newline. Ex: If the input is: 20.0 3.1599 the output is: 3.16 11.85 79.00 Note: Real per-mile cost would also include maintenance and depreciation. 382018.1734836.qxang LAB ACTIVITY 2.21.1: LAB: Driving costs 0/10 5 6 8 LabProgram.java Load default template. public class LabProgram public static void main(String[] args) { /* Type your code here. */ drivingcost(double drivenMiles; double milesPergallon; double dollarspergallon)); { Scanner scnr = new Scanner(System.in); double milesPerGallon; double dollarsPergallon; milesPergallon - scnr.nextDouble(); dollarsPergallon = scnr.nextDouble(); System.out.printf("%.2f", drivingcost(20.0, milesPergallon, dollarsPergallon)); //Finally reaches prints system.out.printf("%.2f", drivingcost(75.6, milesPergallon, dollarsPergallon)); // calls the drivingcost m System.out.printf("%.2f", drivingcost(500.8, milesPergallon, dollarsPergallon)); 1 For drivinacost(20.8, milesPerGallon dollars pergallon), the values --> 20.8, milesPergallon, doLLarspe min 0 0 SM 999 10 11 12 13 14 15 16 17 18 19 2A = 262018. 1734936gxBxg7 LAB ACTIVITY 2.21.1: LAB: Driving costs 0/10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 } 26 LabProgram.java Load default template... milesPerGallon = scnr.nextDouble(); dollarsPergallon = scnr.nextDouble(); System.out.printf("%.2f", drivingcost(20.0, milesPergallon, dollarsPergallon)); //Finally reaches print s System.out.printf("%.2f " drivingcost(75.6, milesPergallon, dollarsPergallon)); // calls the drivingcost m System.out.printf("%.2f", drivingcost(500.8, milesPergallon, dollarsPergallon)); il For drivingcost(20.8, milesPergallon, dollarsPergallon), the values --> (20.8, milesPergallon, doLLarspe // get inputed in public static double drivingcost(doublee drivesiles, double milesPergallon, double dollo // and then the retrun value will store total cost which is then brought back to the print statement to be t // number with two decimal places because of "%.2f" // in is needed to make a new Line after the Last value because system.out.printf does not make a new lines, // doubles Develop mode Submit mode Run your program as often as you'd like, before submitting for grading. Below, type any needed input values in the first box, then click Run program and observe the program's output in the second box. Enter program input (optional) 20.0 3.1599 Run program Input (from above) LabProgram.java (Your program) Output (shown below) Program errors displayed here LabProgram.java:6: error: '.class' expected drivingCost (double drivenMiles; double milesPerGallon; double dollarsPerGallon)); { LabProgram.java:6: error: ';' expected drivingCost (double drivenMiles; double milesPerGallon; double dollarsPerGallon)); { LabProgram.java:25: error: reached end of file while parsing } 3 errors
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
