ConversionTool.java 1.3KB

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