3.17 LAB: Driving costs (expressions) Driving is expensive Write a program with
ID: 3744983 • Letter: 3
Question
3.17 LAB: Driving costs (expressions) Driving is expensive Write a program with a car's miles/galion and gas dollars/galion (both doubles) as input, and output the gas cost for 10 miles, S0 miles, and 400 miles Ex: if the input is 2003.1599, the output is 1.57995 7.89975 63.198 Note Real per-mile cost would also inciude maintenance and depreciation. ACTVETY 3171 LAB Driving costs (expressions) LabProgram.java Load defauit template , inport 5aa.util , scanneri s public class Labproeran Pbic static vyoid naintstringt) args: 0 un your programas oter as youd ike befors supmitting forgreding Beiow type any needed hout valute in the fist bow then ofick Run program and ossenve the prog op mode Submit modeoExplanation / Answer
import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner in = new Scanner(System.in); double milesPerGallon = in.nextDouble(); double dollarsPerGallon = in.nextDouble(); double gasCostFor10 = (10 / milesPerGallon) * dollarsPerGallon; double gasCostFor50 = (50 / milesPerGallon) * dollarsPerGallon; double gasCostFor400 = (400 / milesPerGallon) * dollarsPerGallon; System.out.println(gasCostFor10 + " " + gasCostFor50 + " " + gasCostFor400); } }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.