English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I need to find volume of liquid in a cylindrical tank, the liquid height is a variable. I need to find the volume at each level in intervals of 2" in a 40 feet tank with a radius of 18.8 ft.

2007-08-05 16:44:21 · 2 answers · asked by Charlie 1 in Computers & Internet Programming & Design

2 answers

import java.text.DecimalFormat;
public class MyClass {
static final double radius = 18.8;
static final DecimalFormat VFMT = new DecimalFormat("0.###");

public static void main(String[] args) {
for (int feet=0; feet<=40; ++feet) {
for (int inches=0; inches<12; inches+=2) {
double depth = ((double) feet) + (1.0 / 12.0) * ((double) inches);
double volume = Math.PI * radius * radius * depth;
System.out.println("" + feet + "ft, " + inches + "in: vol = " + VFMT.format(volume) + " ft^3");
if (feet == 40) inches = 12; // Skip to end after 40'0"
} } } }

=====================
Output:

0ft, 0in: vol = 0 ft^3
0ft, 2in: vol = 185.061 ft^3
0ft, 4in: vol = 370.122 ft^3
0ft, 6in: vol = 555.182 ft^3
0ft, 8in: vol = 740.243 ft^3
0ft, 10in: vol = 925.304 ft^3
1ft, 0in: vol = 1110.365 ft^3
1ft, 2in: vol = 1295.425 ft^3
1ft, 4in: vol = 1480.486 ft^3
[...]
39ft, 10in: vol = 44229.52 ft^3
40ft, 0in: vol = 44414.58 ft^3

2007-08-05 17:07:36 · answer #1 · answered by McFate 7 · 0 0

import java.io.*;

public class TankVolume {

static double tank_volume(double L,double R,double e,double y) {
double q = Math.sqrt((2 * R / y)-1);
double a = 2 * L * Math.atan2(1,q) * R * R;
double b = (e * Math.PI * (3 * R-y)* y*y) / 3.0;
double c = L * Math.sqrt((2 * R-y) * y) * (y-R);
return a + b + c;
}

static public void main(String[] args) throws Exception {
if(args.length != 4) {
System.out.println("Usage: L (cylinder length)");
System.out.println(" R (cylinder radius/ellipse major radius)");
System.out.println(" r (ellipse minor radius)");
System.out.println(" y (content height, max 2R)");
System.out.println(" All consistent units.");
System.out.println("Result: tank partial content volume in units^3.");
}
else {
double L = Double.parseDouble(args[0]);
double R = Double.parseDouble(args[1]);
double r = Double.parseDouble(args[2]);
double e = r/R;
double y = Double.parseDouble(args[3]);
double v = tank_volume(L,R,e,y);
System.out.println("Tank partial volume: " + v);
}
}
};

2007-08-06 01:23:51 · answer #2 · answered by angel04 3 · 0 0

fedest.com, questions and answers