Can you help me create a needsGallons() method in JAVA code based on the senario below?
Alastair Brewster owns a bar. His most famous offering is a pint of Silky Dark, a beer his patrons are very found of.
In order to plan ahead, he needs to order the beer by the gallon because his supplier does not bother dealing with smaller quantities.
To help Alastair, create a public static method called neededGallons, which takes an integer number of pints and returns the number of gallons
Alastair needs to order to cover for those pints. The number of returned gallons needs to be an integer (int).
If the calculated number of gallons is not an integer type, round up. Alastair will be happy to “dispose” of the extra pints!
To prevent Alastair’s son from ordering a crazy number of gallons (as if to quench all of England’s thirst), the inputted number of pints must be between 0 and 5000.
For any other value, the method should return -1.
Hints:
For this example, an easy way to round up is: add 0.9 and trim the decimals. This ‘trick’ DOES NOT APPLY to general cases.
In general, you should use Math.ceil to round up.
Oh! By the way, it takes 8 pints to make a gallon
/**************************************************************************************************/
public class Pints {
// Create your neededGallons() method here
// Use main method below for testing (optional)
public static void main(String[] args) {
System.out.println(“Gallons: ” + neededGallons(64));
System.out.println(“Gallons: ” + neededGallons(65));
System.out.println(“Gallons: ” + neededGallons(0));
System.out.println(“Gallons: ” + neededGallons(6000));
}
}