ConversionTool.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import java.lang.Math;
  2. public class ConversionTool {
  3. public static void main(String[] args){}
  4. public static float CentimetersToInches(float centimeters){
  5. if (centimeters < 0){
  6. return 0;}
  7. else{
  8. float answer = centimeters * 0.393701f;
  9. return answer;}
  10. }
  11. public static float InchesToCentimeters(float inches){
  12. if (inches < 0){
  13. return 0;}
  14. else{
  15. float answer = inches * 2.54f;
  16. return answer;}
  17. }
  18. public static float FeetToMeters(float feet){
  19. if (feet < 0){
  20. return 0;}
  21. else{
  22. float answer = feet * 0.3048f;
  23. return answer;}
  24. }
  25. public static float MetersToFeet(float meters){
  26. if (meters < 0){
  27. return 0;}
  28. else{
  29. float answer = meters * 3.28084f;
  30. return answer;}
  31. }
  32. public static float MphToKph(float mph){
  33. if (mph < 0){
  34. return 0;}
  35. else{
  36. float answer = mph * 1.60934f;
  37. return answer;}
  38. }
  39. public static float KphToMph(float kph){
  40. if (kph < 0){
  41. return 0;}
  42. else{
  43. float answer = kph * 0.621371f;
  44. return answer;}
  45. }
  46. public static float CelsiusToFahrenheit(float celsius){
  47. float answer = (celsius * 1.8f)+32;
  48. return answer;
  49. }
  50. public static float FahrenheitToCelsius(float fahrenheit){
  51. float answer = (fahrenheit-32)/1.8f;
  52. return answer;
  53. }
  54. }