Question: Write a program that asks the user to input a certain volume in liters as a number with an integer and a fractional part (digits

 Write a program that asks the user to input a certain

Write a program that asks the user to input a certain volume in liters as a number with an integer and a fractional part (digits after the dot). Then convert the number to US units: gallons, quarts, pints, cups and fluid Ounces. Start by converting the amount in liters into fluid Ounces: 1 fl oz = 0.02957352956251 (liters). As you divide a real number by a real number, the result is also a real number. Then convert the amount in fluid Ounces into an integer number of cups: 8 fl oz = 1 cup. Divide the fluid ounces by 8 and store them as an integer. To store the result of a division of a real number (a double by another number as an integer, a cast needs to be used in Java. The division might result in a remainder. So compute the rest of fluid Ounces as well: reconvert the amount in cups to fluid Ounces and subtract this amount from the original fluid Ounce number. This is the rest that will stay a real number of fluid Ounces. Then convert the integer number of cups to pints: 1 pint = 2 cups. Compute also the remainder of that integer division, which gives you the cup amount. Continue the same way with quarts: 1 quart = 2 pints. Finally convert the quarts to gallons: 1 gallon = 4 quarts. An example of such a computation is: Let I = 5.25 be the amount in liters. This is f = 1/0.0295735295625 = 177.523619184675735 total fluid Ounces. This amount contains c = (int) (f/8) = 22 cups with remaining oz = f-8*C = 1.523619184675735 fluid Ounces. These are p = c/2 = 11 pints. There are no cups left: c = c % 2 = 0. These are q = p /2 = 5 quarts. There is 1 pint left: p = p%2 = 1 This is g = 9/4 = 1 gallon. There is 1 quart left: q = q % 4 = 1. So the program would display: Please enter a volume in liters: 5.25 This volume of 5.25 liter(s) is equivalent to 1 gallon(s), 1 quart(s), 1 pint(s). O cup(s) and 1.523619184675735 fluid Ounce(s). Grading: 10 points total 9 points via zyBooks 1 point for documentation & style o e.g. proper indentation, good variable names with proper capitalization LAB 20.3.1: a1, #3 Conversion from metric to US units for volumes 0190 Volumes.java Load default template... import java.util.Scanner; public class Volumes ? public static void main(String[] args) { /* Type your code here. */ 7 )

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!