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
Step: 1
Heres an example implementation of the class with the required static methods java public class Gall...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started