ConversionTool.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. public class ConversionTool {
  2. public static final float CM_CONVERT = 0.3937008f;
  3. public static final float IN_CONVERT = 2.54f;
  4. public static final float FT_CONVERT = 3.28f;
  5. public static final float M_CONVERT = 0.3048f;
  6. public static final float CELSIUS_CONVERT = 1.8f;
  7. public static final float CELSIUS_CSTNT2 = 32.0f;
  8. public static final float FAHRENHT_CONVERT = 32.0f;
  9. public static final float FAHRENHT_CSTNT2 = 5.0f;
  10. public static final float FAHRENHT_CSTNT3 = 9.0f;
  11. public static final float MPH_CONVERT = 1.6093440f;
  12. public static final float KPH_CONVERT = 0.6214f;
  13. public static float cmToInches;
  14. public static float inchesToCm;
  15. public static float ftToMeters;
  16. public static float metersToFt;
  17. public static float mphToKph;
  18. public static float kphToMph;
  19. public static void main(String[] args){}
  20. public static float CentimetersToInches(float centimeters){
  21. cmToInches = centimeters * CM_CONVERT;
  22. if(cmToInches < 0) {return 0f;}
  23. else
  24. return cmToInches;
  25. }
  26. public static float InchesToCentimeters(float inches){
  27. inchesToCm = inches * IN_CONVERT;
  28. if(inchesToCm < 0) {return 0f;}
  29. else
  30. return inchesToCm;
  31. }
  32. public static float FeetToMeters(float feet){
  33. ftToMeters = feet / FT_CONVERT;
  34. if(ftToMeters < 0) {return 0f;}
  35. else
  36. return ftToMeters;
  37. }
  38. public static float MetersToFeet(float meters){
  39. metersToFt = meters / M_CONVERT;
  40. if(metersToFt < 0) {return 0f;}
  41. else
  42. return metersToFt;
  43. }
  44. public static float CelsiusToFahrenheit(float celsius){
  45. return (CELSIUS_CONVERT * celsius) + CELSIUS_CSTNT2;
  46. }
  47. public static float FahrenheitToCelsius(float fahrenheit){
  48. return ((fahrenheit - FAHRENHT_CONVERT) * FAHRENHT_CSTNT2) / FAHRENHT_CSTNT3;
  49. }
  50. public static float MphToKph(float mph){
  51. mphToKph = mph * MPH_CONVERT;
  52. if(mphToKph < 0) {return 0f;}
  53. else
  54. return mphToKph;
  55. }
  56. public static float KphToMph(float kph){
  57. kphToMph = kph * KPH_CONVERT;
  58. if(kphToMph < 0) {return 0f;}
  59. else
  60. return kphToMph;
  61. }
  62. }