galinyotsev123

ProgBasics03Conditional-Statements-Y04MetricConverter

Jan 11th, 2019
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Y04MetricConverter {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. double inputMetricNumber = Double.parseDouble(scanner.nextLine());
  8. String inputMetric = scanner.nextLine();
  9. String outputMetric = scanner.nextLine();
  10.  
  11. double convertedToMeter = 0;
  12. double convertedToOutputMetric = 0;
  13.  
  14. if ("m".equalsIgnoreCase(inputMetric)) {
  15. convertedToMeter = inputMetricNumber;
  16. } else if ("mm".equalsIgnoreCase(inputMetric)) {
  17. convertedToMeter = inputMetricNumber / 1000;
  18. } else if ("cm".equalsIgnoreCase(inputMetric)) {
  19. convertedToMeter = inputMetricNumber / 100;
  20. } else if ("mi".equalsIgnoreCase(inputMetric)) {
  21. convertedToMeter = inputMetricNumber / 0.000621371192;
  22. } else if ("in".equalsIgnoreCase(inputMetric)) {
  23. convertedToMeter = inputMetricNumber / 39.3700787;
  24. } else if ("km".equalsIgnoreCase(inputMetric)){
  25. convertedToMeter = inputMetricNumber * 1000;
  26. } else if ("ft".equalsIgnoreCase(inputMetric)){
  27. convertedToMeter = inputMetricNumber / 3.2808399;
  28. } else if ("yd".equalsIgnoreCase(inputMetric)) {
  29. convertedToMeter = inputMetricNumber / 1.0936133;
  30. }
  31.  
  32. if ("m".equalsIgnoreCase(outputMetric)) {
  33. convertedToOutputMetric = convertedToMeter;
  34. } else if ("mm".equalsIgnoreCase(outputMetric)) {
  35. convertedToOutputMetric = convertedToMeter * 1000;
  36. } else if ("cm".equalsIgnoreCase(outputMetric)) {
  37. convertedToOutputMetric = convertedToMeter * 100;
  38. } else if ("mi".equalsIgnoreCase(outputMetric)) {
  39. convertedToOutputMetric = convertedToMeter * 0.000621371192;
  40. } else if ("in".equalsIgnoreCase(outputMetric)) {
  41. convertedToOutputMetric = convertedToMeter * 39.3700787;
  42. } else if ("km".equalsIgnoreCase(outputMetric)){
  43. convertedToOutputMetric = convertedToMeter / 1000;
  44. } else if ("ft".equalsIgnoreCase(outputMetric)){
  45. convertedToOutputMetric = convertedToMeter * 3.2808399;
  46. } else if ("yd".equalsIgnoreCase(outputMetric)) {
  47. convertedToOutputMetric = convertedToMeter * 1.0936133;
  48. }
  49.  
  50. System.out.printf("%.8f", convertedToOutputMetric);
  51. }
  52. }
Add Comment
Please, Sign In to add comment