ConversionTool.java 1.3KB

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