ConversionTool.java 1.9KB

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