ConversionTool.java 1.6KB

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