Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java, please. I've given myself a headache. 1.30 LAB: Driving costs Driving is expensive. Write a program with a cars miles/gallon and gas dollars/gallon (both

Java, please. I've given myself a headache.

image text in transcribed

image text in transcribed

image text in transcribed

1.30 LAB: Driving costs Driving is expensive. Write a program with a cars miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Qutput 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.03.1599 the output is: 3.1811.8579.00 Note: Tee permile cost wou d also include mantenance and depreciation. import java.util.Scanner; public class LabProgram \{ public static void main(String[] args) \{ Scanner obj = new Scanner(System.in); double car_mile =obj.nextDouble(); double dolitar = obj.nextDouble(); double twenty_miles =( dollar*20.0)/car_mile; double seventyfive_miles =( dollar*75.0)/car_mile; double fivehundred_miles =( dollar*500.0)/car_mile; System.out.printf("\%.2f \%.2f \%.2f", twenty_miles, seventyfive_miles, fivehundred_miles); \} Output is nearly correct, but whitespace differs. See highlights below. Input Your output Expected output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

More Books

Students also viewed these Databases questions

Question

1. Practice giving the test before you actually use it.

Answered: 1 week ago