ConversionTool.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. public class ConversionTool {
  2. public static void main(String[] args){
  3. }
  4. public static float CentimetersToInches(float centimeter){
  5. if(centimeter > 0)
  6. {
  7. float inches = (float)0.3937 * centimeter;
  8. return inches;
  9. }
  10. else
  11. return 0;
  12. }
  13. public static float InchesToCentimeters(float inches){
  14. if(inches > 0)
  15. {
  16. float centimeter = (float)2.54 * inches;
  17. return centimeter;
  18. }
  19. else
  20. return 0;
  21. }
  22. public static float FeetToMeters(float feet){
  23. if(feet > 0)
  24. {
  25. float meter = (float)0.3048 * feet;
  26. return meter;
  27. }
  28. else
  29. return 0;
  30. }
  31. public static float MetersToFeet(float meter){
  32. if(meter > 0)
  33. {
  34. float feet = (float)3.28084 * meter;
  35. return feet;
  36. }
  37. else
  38. return 0;
  39. }
  40. public static float CelsiusToFahrenheit(float celsius){
  41. if(celsius > 0)
  42. {
  43. float fahrenheit =(float) (celsius* 1.8 + 32);
  44. return fahrenheit;
  45. }
  46. else
  47. return 0;
  48. }
  49. public static float FahrenheitToCelsius(float fahrenheit){
  50. if(fahrenheit > 0)
  51. {
  52. float celsius = (float)((fahrenheit -32 )* 0.5556);
  53. return celsius;
  54. }
  55. else
  56. {
  57. return 0;
  58. }
  59. }
  60. public static float MphToKph(float mph){
  61. if(mph > 0)
  62. {
  63. float kph = (float)1.60934 * mph;
  64. return kph;
  65. }
  66. else
  67. return 0;
  68. }
  69. public static float KphToMph(float kph){
  70. if(kph > 0)
  71. {
  72. float mph = (float)0.621371 * kph;
  73. return mph;
  74. }
  75. else
  76. return 0;
  77. }
  78. }