ConversionTool.java 1.7KB

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