Iniciar sesiónCrear cuenta

# Estadísticas del código: convertir la presión a varias unidades - Java

## convertir la presión a varias unidades

### Java

Publicado el 2 de Enero del 2023 por Flavio Clever (2 códigos)
439 visualizaciones desde el 2 de Enero del 2023
import javax.swing.JOptionPane;
public class PressurreConverter{
public static String[] factorPressure(float value,String UnitToConverte, String ToUnitUnit){
String[] valuePressure=new String[2];
String[] Unit={"psi","atms.","in_H2O","mmH2O","cmH2O","oz/in²","Kg/cm²","in_Hg","mmHg(Torr)","cmHg","mbar","bar","Pa(N/m²)","kPa","MPa"};
// search point ubication
int x=0,y=0;
while(!UnitToConverte.equals(Unit[x])){x++;}
while(!ToUnitUnit.equals(Unit[y])){y++;}
//calculate to return
float[] factores={1f,14.7f,0.0361f,0.001421f,0.01421f,0.0625f,14.22f,0.4912f,0.01934f,0.1934f,0.0145f,14504f,0.000145f,0.14504f,145.04f,
0.0681f,1f,0.00246f,0.000097f,0.000967f,0.00425f,0.968f,0.03342f,0.001316f,0.01316f,0.000987f,0.987f,0.00001f,0.00987f,9869f,
27.71f,407.2f,1f,0.0394f,0.3937f,1732f,394.1f,13.61f,0.536f,5358f,0.4012f,401.9f,0.00402f,4019f,4019f,
703.8f,10343f,25.4f,1f,10f,43986f,100010f,345.7f,13.61f,136.1f,10.21f,10210f,0.102f,102.07f,102074f,
70.38f,1034.3f,2.54f,0.1f,1f,4.4f,1001f,34.57f,1361f,13.61f,1021f,1021f,0.0102f,10207f,10207f,
16f,235.1f,0.5775f,0.0227f,0.227f,1f,227.6f,7858f,0.31f,3.1f,0.2321f,232.1f,0.00232f,2321f,2321f,
0.0704f,1033f,0.00254f,0.0001f,0.001f,0.0044f,1f,0.0345f,0.00136f,0.0136f,0.00102f,1.02f,0.00001f,0.0102f,10.2f,
2036f,29.92f,0.0735f,0.00289f,0.0289f,0.1273f,28.96f,1f,0.0394f,0.394f,0.0295f,29.53f,0.000295f,0.295f,295.3f,
51715f,760f,1866f,0.0735f,0.735f,3232f,735.6f,25.4f,1f,10f,0.75f,750f,0.0075f,7.5f,7500f,
5.17f,76f,0.187f,0.00735f,0.0735f,0.3232f,73.56f,2.54f,0.1f,1f,0.075f,75f,0.00075f,0.75f,750f,
68.95f,1013f,2488f,0.098f,0.98f,4.31f,980.7f,33.86f,1333f,13.33f,1f,1000f,0.01f,10f,10000f,
0.0689f,1013f,0.00249f,0.000098f,0.00098f,0.00431f,0.981f,0.0339f,0.001333f,0.01333f,0.001f,1f,0.00001f,0.01f,10f,
6895f,101325f,248.8f,9.8f,98f,431f,98067f,3386f,133.3f,1333f,100f,100000f,1f,1000f,1000000f,
6895f,101.3f,0.249f,0.0098f,0.098f,0.431f,98.07f,3386f,0.1333f,1333f,0.1f,100f,0.001f,1f,1000f,
0.0069f,0.1013f,0.00025f,0.00001f,0.0001f,0.00043f,0.0981f,0.00339f,0.000133f,0.00133f,0.0001f,0.1f,0.000001f,0.001f,1f};

float[][] factor=new float[15][15];
for (int i=0;i<15;i++){
for(int j=0;j<15;j++){
factor[i][j]=switch(i){
case 0->factores[j];
case 1->factores[15+j];
case 2->factores[30+j];
case 3->factores[45+j];
case 4->factores[60+j];
case 5->factores[75+j];
case 6->factores[90+j];
case 7->factores[105+j];
case 8->factores[15*8+j];
case 9->factores[15*9+j];
case 10->factores[15*10+j];
case 11->factores[15*11+j];
case 12->factores[15*12+j];
case 13->factores[15*13+j];
default->factores[15*14+j];
};
System.out.print(" "+factor[i][j]+" ");
}
System.out.println();
}
System.out.println("factor ans:"+factor[y][x]);
System.out.println("ans:"+value*factor[y][x]);
valuePressure[0]=Float.toString(value*factor[y][x]);
valuePressure[1]=ToUnitUnit;
return valuePressure;
}
public static void main(String[] args) {
new Object[]{"psi","atms.","in_H2O","mmH2O","cmH2O","oz/in²","Kg/cm²","in_Hg","mmHg(Torr)","cmHg","mbar","bar","Pa(N/m²)","kPa","MPa"},"atms.");
float valor=Float.parseFloat(JOptionPane.showInputDialog("Ingrese la pression"));