Answered step by step
Verified Expert Solution
Link Copied!

Question

...
1 Approved Answer

First, launch IntelliJ and close any previous projects that may be open (at the top menu go to File ==> Close All Projects). Then create

First, launch IntelliJ and close any previous projects that may be open (at the top menu go to File ==> Close All Projects).

Then create new Java application called "FuelCalculation" (without the quotation marks) that will compute the the cost to travel 50 miles and the distance that the car can travel with the gas currently in the tank.

Using a Scanner object, request the following three double values from the user after a user-friendly output statement or prompt for each:

  • Number of gallons of gas in the tank
  • Fuel efficiency of the car in miles per gallon
  • Price of gas per each gallon

Compute how far, in miles, the vehicle can travel on the available fuel. Your program should output:

You are able to travel X.XX miles on remaining fuel.

where X.XX is the miles distance you calculated.

Compute how much the cost would be for the gas to travel 50 miles. Your program should output:

It will cost $XX.XX to travel 50 miles in the vehicle.

where XX.XX is the cost to travel 50 miles.

Notice the use of 2 decimal places required in your program output: Use System.out.printf("It will cost $.2f to travel 50 miles in the vehicle. ", travelCost);

For this and all upcoming PA's involving user input, use a Scanner object to capture input. Do not use a command (terminal) prompt. Be sure to use "valid" and "reasonable" data values for input.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Introduction To Health Care Management

Authors: Sharon B. Buchbinder, Nancy H. Shanks

3rd Edition

9781284081015

Students also viewed these Algorithms questions