Question: 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

1 Expert Approved Answer
Step: 1 Unlock

Heres an example implementation of the class with the required static methods java public class Gall... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!