How can I change this code to make variable operation2
working in second switch
function.
When I do parseDouble
it gets error bla bla parsedouble
.
It doesn't work even if I try to create global operation2
.
package matura;
import java.util.Scanner;
public class MeasureUnits {
public static void main(String args[])
{
String operation;
String operation2;
Scanner value = new Scanner(System.in);
System.out.println(" Write value: :");
double wartość;
wartość = value.nextDouble();
double yard, inch, foot, mile;
double metr, decymetr, centymetr, kilometr;
centymetr = 1;
metr = 100 * centymetr;
centymetr = 1;
kilometr = centymetr * 100000;
decymetr = 10 * centymetr;
yard = 0.9144 * metr;
inch = 2.54 * centymetr;
mile = 1.609344 * kilometr;
foot = 30.48 * centymetr;
Scanner input1 = new Scanner(System.in);
System.out.println(" Choose one of measure units" + " 'yard' 'inch' 'feet' 'mile' :");
operation2 = input1.next();
switch (operation2) {
case "yard":
System.out.println("You've choosed 'yard' ");
break;
case "inch":
System.out.println(" You've choosed 'inch'");
break;
case "mile":
System.out.println(" You've choosed 'mile'");
break;
case "foot":
System.out.println("You've choosed 'foot'");
break;
}
{
Scanner input2 = new Scanner(System.in);
System.out.println(" Choose one of polish measure units" + " 'metr' 'centymetr' 'decymetr' 'kilometr' :");
operation = input2.next();
switch (operation) {
case "metr":
System.out.println(operation2 * wartość / 100);
break;
case "centymetr":
System.out.println(operation2 * wartość / 100);
break;
case "kilometr":
System.out.println(operation2 * wartość / 100000);
break;
case "decymetr":
System.out.println(operation2 * wartość / 10);
break;
}
}
}