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