ConversionTool.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. public class ConversionTool {
  2. public static void main(String[] args){
  3. }
  4. public static float CentimetersToInches(float centimeters){
  5. if(centimeters > 0){
  6. return centimeters * (float) 0.393701;
  7. }
  8. return 0;
  9. }
  10. public static float InchesToCentimeters(float inches){
  11. if(inches > 0){
  12. return inches / (float) 0.393701;
  13. }
  14. return 0;
  15. }
  16. public static float FeetToMeters(float feet){
  17. if (feet > 0){
  18. return feet * (float) 0.3048;
  19. }
  20. return 0;
  21. }
  22. public static float MetersToFeet(float meters){
  23. if (meters > 0){
  24. return meters / (float) 0.3048;
  25. }
  26. return 0;
  27. }
  28. public static float CelsiusToFahrenheit(float celsius){
  29. return (celsius * (float)1.8) + 32;
  30. }
  31. public static float FahrenheitToCelsius(float fahrenheit){
  32. return (fahrenheit - 32) / (float)1.8;
  33. }
  34. public static float MphToKph(float mph){
  35. if (mph > 0){
  36. return mph * (float) 1.60934;
  37. }
  38. return 0;
  39. }
  40. public static float KphToMph(float kph){
  41. if (kph > 0){
  42. return kph / (float) 1.60934;
  43. }
  44. return 0;
  45. }
  46. }