Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Compose a class and, in this class, create two static methods: 1. A method called gallonsToLiters , which takes a single double parameter called gallons



Compose a class and, in this class, create two static methods:

1. A method called gallonsToLiters, which takes a single double parameter called gallons and returns a long.


The method should simply return the number of liters (rounded) corresponding to the number of gallons given as the method argument.


The method should return -1 if the gallons argument is less than 0.


2. A main method to demonstrate your gallonsToLiters method. Use the gallon values given below.


3. Compose an additional method called gallonsToLitersDec, which works like the gallonsToLiters method above, but returns a double. The return value should be the number of liters corresponding to the number of gallons given as the method argument, rounded to 3 decimal places.

Note: 1 gallon = 3.785411784 liters.


Sample output:

Gallons Liters Rounded Liters Rounded 3 Decimals
1 4 3.785
5 19 18.927
-2 1 -1.0
12.5 47 47.318
1/3.785411784 1 1.0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Heres an example implementation of the class with the required static methods java public class Gall... 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

Java An Introduction To Problem Solving And Programming

Authors: Walter Savitch

8th Edition

0134462033, 978-0134462035

More Books

Students also viewed these Programming questions

Question

Case : Karl and June Monroe

Answered: 1 week ago