Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A car with a 20-gallon gas tank averages 21.5 miles per gallon when driven in town and 26.8 miles per gallon when driven on the

A car with a 20-gallon gas tank averages 21.5 miles per gallon when driven in town and 26.8 miles per gallon when driven on the highway. Write a program that calculates and displays the distance the car can travel on one tank of gas when driven in town and when driven on the highway.

Please write it in java, and then type it in your response so that I can copy it down! Here is the already existing source code that you need to adjust and edit to complete the problem:

import java.util.Scanner; // Scanner is in the java.util package

public class Main { public static void main(String[] args) { // Create a Scanner object Scanner input = new Scanner(System.in); // Take input for milage in town System.out.print("Enter milage in town: "); double milageTown = input.nextDouble();

// Take input for milage in highway System.out.print("Enter milage in highway: "); double milageHighway = input.nextDouble();

// Take input for size of tank System.out.print("Enter size of tank: "); double sizeTank = input.nextDouble();

/*double sizeTank = 20.0; double milageHighway = 26.8; double milageTown = 21.5; */

// Compute distance travelled in town double distanceTown = milageTown * sizeTank;

// Compute distance travelled in highway double distanceHighway = milageHighway * sizeTank;

// Display result System.out.println("The Distance in Town " + distanceTown + " Distance in Highway " + distanceHighway); } }

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 Concepts

Authors: David Kroenke, David J. Auer

3rd Edition

0131986252, 978-0131986251

More Books

Students also viewed these Databases questions