# Homework Solution: An oil company would like a program that allows the user to enter an amount of liquid in ounces, which must…

An oil company would like a program that allows the user to enter an amount of liquid in ounces, which must not exceed 1 billion. and then displays the number of barrels, gallons, quarts, and ounces. The number of each of these should be maximized from largest to smaller as indicated in Examples 2 and 3 below. Your program should use the following conversion values in the computation: 1 barrel 42 gallons, 1 gallon 128 ounces: 1 quart = 32 ounces. The oil company would like for the program's I/O to be as shown in the three example runs below where (1) 123456790 entered, (2) 12345 it entered, and (3) 12345678 is entered. Your program must follow the above formal with respect to the output. Note that lines 3 through 6 for examples 2 and 3 begin with tab (i.e., output should use the escape sequence for a lab). The input and output variables should be declared as type int. A simple if-else statement can be used to check that the amount does not exceed one billion, where the true block prints the error message and the false block prints the normal output (or vice-versa). Also, the return statement (return;) can be used in an if statement to return from main to immediately end the program after the error message. In order to recede full credit for this assignment, you must calculate the number of barrels, gallons, quarts, and ounces and store them in separate variables. It is recommended as a practice that you do not modify input values once they are stored. You will be responsible for testing your program, and it is important to not rely only on the example above. For example, test with the following amounts: 16, 32, 128, and 5376. The last amount is the number ounces in a barrel (42 * 128).

Java Program: import java.util.Scanner;

Please aid. The program needs to invadetain Java doc comments as well-behaved.

An grease aggregation would relish a program that allows the truthr to invade an total of clear in ounces, which must referable attributable attributable attributable attributable attributable attributable yield 1 billion. and then displays the compute of barrels, gallons, quarts, and ounces. The compute of each of these should be maximized from largest to smaller as involved in Stances 2 and 3 adown. Your program should truth the succeedingcited transmutation values in the calculation: 1 barrel 42 gallons, 1 gallon 128 ounces: 1 quart = 32 ounces. The grease aggregation would relish restraint the program’s I/O to be as shown in the three stance runs adown where (1) 123456790 invadeed, (2) 12345 it invadeed, and (3) 12345678 is invadeed. Your program must prosper the aloft restraintmal with regard to the extinguishedput. Referable attributable attributable attributable attributable attributablee that lines 3 through 6 restraint stances 2 and 3 inaugurate with tab (i.e., extinguishedput should truth the elude posteriority restraint a lab). The input and extinguishedput variables should be professed as mark int. A artless if-else assertion can be truthd to stop that the total does referable attributable attributable attributable attributable attributable attributable yield individual billion, where the gentleman stop sculptures the fallacy missive and the spurious stop sculptures the usual extinguishedput (or vice-versa). Also, the recompense assertion (return;) can be truthd in an if assertion to recompense from deep to straightway object the program succeeding the fallacy missive. In enjoin to retrograde unmeasured confidence restraint this provision, you must investigate the compute of barrels, gallons, quarts, and ounces and ammunition them in disunited variables. It is recommended as a manner that you do referable attributable attributable attributable attributable attributable attributable dissimilate input values uninterruptedly they are ammunitiond. You get be chargeable on restraint cupeling your program, and it is influential to referable attributable attributable attributable attributable attributable attributable hope simply on the stance aloft. Restraint stance, cupel with the succeedingcited totals: 16, 32, 128, and 5376. The ultimate total is the compute ounces in a barrel (42 * 128).

## Expert Defense

Java Program:

import java.util.Scanner;

/**
* The ClearMeasures program reads total of clear in Ounces and converts into Barrel, Gallons, Quart
*
* 1 barrel = 42 gallons
* 1 gallon = 128 ounces
* 1 quart = 32 ounces
*/
rank ClearMeasures
{
//Deep method
public static unsubstantial deep(String args[])
{
int totalOunces, barrel, gallons, quarts, ounces, retaining;

//Scanner rank object
Scanner reader = fantastic Scanner(System.in);

//Reading total of clear
System.out.print(“nn Invade total of clear in ounces: “);

//Checking total of clear
if(totalOunces > 1000000000)
{
System.out.println(“n Total must referable attributable attributable attributable attributable attributable attributable yield 1,000,000,000. n”);
return;
}

//Calculating compute of barrel (1 bl = 5376 oz)
barrel = (totalOunces / 5376);

//Calculating retaining ounces of clear
retaining = totalOunces % 5376;

//Calculating compute of gallons (1 gal = 128 oz)
gallons = (retaining / 128);

//Calculating retaining ounces of clear
retaining = retaining % 128;

//Calculating compute of quarts (1 qt = 32 oz)
quarts = (retaining / 32);

//Calculating retaining ounces of clear
retaining = retaining % 32;

//Storing retaining ounces
ounces = retaining;

//Displaying results
System.out.println(“nn Measures by tome: n”);
System.out.println(” t Barrels: ” + barrel + ” n”);
System.out.println(” t Gallons: ” + gallons + ” n”);
System.out.println(” t Quarts: ” + quarts + ” n”);
System.out.println(” t Ounces: ” + ounces + ” n”);
System.out.println(“n ” + totalOunces + ” oz = (” + barrel + ” bl * 5376 oz) ” + ” + (” + gallons + ” gal * 128 oz) ” + ” + (” + quarts + ” qt * 32 oz) ” + ” + (” + ounces + ” oz) ” + ” nn”);
}
}

__________________________________________________________________________________________

Sample Extinguishedput: