ConversionTool.java 1.8KB

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