-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOilUnits.java
More file actions
55 lines (50 loc) · 1.52 KB
/
OilUnits.java
File metadata and controls
55 lines (50 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import java.util.Scanner;
/**
* Takes amount of oil in ounces and converts to barrels, gallons, quarts, and ounces.
*
* @author Adam Bostwick
* @version 9/10/19
*/
public class OilUnits
{
/** @param args Command line arguments (not used). */
public static void main(String[] args)
{
Scanner userInput = new Scanner(System.in);
int max = 1000000000;
String inputOzString = "";
int inputOz = 0;
int bl = 0;
int gal = 0;
int qt = 0;
int oz = 0;
System.out.print("Enter amount of oil in ounces: ");
inputOzString = userInput.nextLine();
userInput.close();
try {
inputOz = Integer.parseInt(inputOzString);
} catch (NumberFormatException e) {
System.out.println("Input is not a valid integer");
System.exit(0);
}
if (inputOz >= max)
{
System.out.print("Amount must not exceed 1,000,000,000.");
}
else
{
bl = inputOz / 5376;
oz = inputOz % 5376;
gal = oz / 128;
oz = oz % 128;
qt = oz / 32;
oz = oz % 32;
System.out.print("Oil amount in units:\n\tBarrels: " + bl);
System.out.print("\n\tGallons: " + gal + "\n\tQuarts: " + qt);
System.out.print("\n\tOunces: " + oz);
System.out.print("\n" + inputOz + " oz = (" + bl);
System.out.print(" bl * 5376 oz) + (" + gal + " gal * 128 oz) + (");
System.out.print(qt + " qt * 32 oz) + (" + oz + " oz)");
}
}
}