MetricConverter, задача 8
Здравейте,
решението на тази задача се опитах да го направя аналогично на Currency Converter, но нещо не тръгва. Дори не иска да се компилира. Дали може някой да го погледне и да ми помогне да намеря грешката си:
package com.company; import java.util.Scanner; /** * Created by Daniela on 10/12/2016. */ public class MetricConverter { public static void main(String [] args) { Scanner console = new Scanner(System.in); double var = Double.parseDouble(console.nextLine()); System.out.printf("Select unit1: m, mm, cm, mi, in, km, ft, yd"); String unit1 = console.nextLine(); System.out.printf("Select unit2: m, mm, cm, mi, in, km, ft, yd"); String unit2 = console.nextLine(); double source = 0; double target = 0; double m = 1; double mm = 1.001; double cm = 1.01; double mi = 1 / 0.000621371192; double in = 1 / 39.3700787; double km = 1 / 1.001; double ft = 1 / 3.2808399; double yd = 1 / 1.0936133; if (unit1.equals("m")) { source = m; } else if (unit1.equals("mm")) { source = mm; } else if (unit1.equals("cm")) { source = cm; } else if (unit1.equals("mi")) { source = mi; } else if (unit1.equals("in")) { source = in; } else if (unit1.equals("km")) { source = km; } else if (unit1.equals("ft")) { source = ft; } else if (unit1.equals("yd")) { source = yd; } if (unit2.equals("m")) { target = m; } else if (unit1.equals("mm")) { target = mm; } else if (unit1.equals("cm")) { target = cm; } else if (unit1.equals("mi")) { target = mi; } else if (unit1.equals("in")) { target = in; } else if (unit1.equals("km")) { target = km; } else if (unit1.equals("ft")) { target = ft; } else if (unit1.equals("yd")) { target = yd; } System.out.println("Result: %f", var*source=target); } }