ConversionTool.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. public class ConversionTool {
  2. private static final float CENT_TO_INCH = (float) 2.54;
  3. public static void main(String[] args){}
  4. public static float CentimetersToInches(float centimeters){
  5. float inches = centimeters / CENT_TO_INCH;
  6. return ifNegGetZero(inches);
  7. }
  8. public static float InchesToCentimeters(float inches){
  9. float centimeters = inches * CENT_TO_INCH;
  10. return ifNegGetZero(centimeters);
  11. }
  12. public static float FeetToMeters(float feet){
  13. float meters = feet / (float)3.28;
  14. return ifNegGetZero(meters);
  15. }
  16. public static float MetersToFeet(float meters){
  17. float feet = meters * (float)3.2808;
  18. return ifNegGetZero(feet);
  19. }
  20. public static float CelsiusToFahrenheit(float celsius){
  21. float fahr = celsius * (float)(1.8) + (float)(32);
  22. return fahr;
  23. }
  24. public static float FahrenheitToCelsius(float fahrenheit){
  25. float cels = (fahrenheit - (float)(32)) / (float) (1.8);
  26. return cels;
  27. }
  28. public static float MphToKph(float mph){
  29. float kph = mph * (float)(1.60934);
  30. return ifNegGetZero(kph);
  31. }
  32. public static float KphToMph(float kph){
  33. float mph = kph / (float)(1.60934);
  34. return ifNegGetZero(mph);
  35. }
  36. public static float ifNegGetZero(float number){
  37. if (number >=0) {
  38. return number;
  39. } else {
  40. return 0;
  41. }
  42. }
  43. }