ConversionTool.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. public class ConversionTool {
  2. public static void main(String[] args){
  3. }
  4. public static float CentimetersToInches(float centimeters){
  5. float output;
  6. if(centimeters<0)
  7. {
  8. output=0;
  9. }
  10. else
  11. {
  12. output =(float)0.39370*centimeters;
  13. }
  14. return output;
  15. }
  16. public static float InchesToCentimeters(float inches){
  17. float output;
  18. if(inches<0)
  19. {
  20. output=0;
  21. }
  22. else
  23. {
  24. output =inches/(float)0.39370;
  25. }
  26. return output;
  27. }
  28. public static float FeetToMeters(float feet)
  29. {
  30. float output;
  31. if(feet<0)
  32. {
  33. output=0;
  34. }
  35. else
  36. {
  37. output =feet*(float)(1/3.28);
  38. }
  39. return output;
  40. }
  41. public static float MetersToFeet(float meters)
  42. {
  43. float output;
  44. if(meters<0)
  45. {
  46. output=0;
  47. }
  48. else
  49. {
  50. output =meters*(float)(3.28084);
  51. }
  52. return output;
  53. }
  54. public static float CelsiusToFahrenheit(float celsius)
  55. {
  56. return (float)(celsius*1.8)+32;
  57. }
  58. public static float FahrenheitToCelsius(float fahrenheit)
  59. {
  60. return (float)((fahrenheit-32)/1.8);
  61. }
  62. public static float MphToKph(float mph)
  63. {
  64. // return (float)(1.609344*mph);
  65. float output;
  66. if(mph<0)
  67. {
  68. output=0;
  69. }
  70. else
  71. {
  72. output =(float)(mph*1.609344);
  73. }
  74. return output;
  75. }
  76. public static float KphToMph(float kph)
  77. {
  78. float output;
  79. if(kph<0)
  80. {
  81. output=0;
  82. }
  83. else
  84. {
  85. output =(float)(kph*0.6213711922);
  86. }
  87. return output;
  88. }
  89. }