Skip to content

Commit

Permalink
code fixed - */convert* function runs as intended
Browse files Browse the repository at this point in the history
added options to */convert* function: angle
  • Loading branch information
hafihaf123 committed May 14, 2023
1 parent 5c224c8 commit 2ae2172
Showing 1 changed file with 116 additions and 53 deletions.
169 changes: 116 additions & 53 deletions calculator.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ public static void main(String[] args)
System.out.println("1. prism (p)");
System.out.println("2. quadratic function (q)");
System.out.println("3. trojclenka - rule of three (3)");
System.out.println("4. convert (c)");
String option = sc.nextLine();
res = switch (option) {
case "1", "p", "prism" -> adv.prism();
case "2", "q", "quadratic" -> adv.quadratic();
case "3", "trojclenka", "Ro3" -> adv.trojclenka();
case "4", "convert", "c" -> adv.convert();
default -> "Error_incorrect_input";
};
}
case "/prism" -> res = adv.prism();
case "/quadratic", "/quadr" -> res = adv.quadratic();
case "/trojclenka", "/Ro3" -> res = adv.trojclenka();
case "/convert", "/unit" -> res = adv.convert();
default -> res = "Error";
}
}
Expand Down Expand Up @@ -174,69 +177,129 @@ public String convert()
Scanner sc = new Scanner(System.in);
System.out.print("number: ");
double a = sc.nextDouble();
System.out.println("Unit type: (acc)");
String type = sc.nextLine();
System.out.println("Unit type: (acc angle)");
String type = sc.next();
double x; String unit; String to;
switch (type) {

case "acc":
System.out.println("unit: (m/s^2 ft/s^2 g cm/s^2)");
unit = sc.nextLine();

switch (unit) {
case "m/s^2" -> {
System.out.println("convert to: (ft/s^2 g cm/s^2)");
to = sc.nextLine();
switch (to) {
case "ft/s^2" -> x = a / 0.3048;
case "g" -> x = a / 9.8066;
case "cm/s^2" -> x = a / 0.01;
default -> {
return "Err_incorrect_input";
switch (type) {
case "acc" -> {
System.out.println("unit: (m/s^2 ft/s^2 g cm/s^2)");
unit = sc.next();
switch (unit) {
case "m/s^2" -> {
System.out.println("convert to: (ft/s^2 g cm/s^2)");
to = sc.next();
switch (to) {
case "ft/s^2" -> x = a / 0.3048;
case "g" -> x = a / 9.8066;
case "cm/s^2" -> x = a / 0.01;
default -> {
return "Err_incorrect_input";
}
}
}
}
case "ft/s^2" -> {
System.out.println("convert to: (m/s^2 g cm/s^2)");
to = sc.nextLine();
switch (to) {
case "m/s^2" -> x = a / 3.2808;
case "g" -> x = a / 32.174;
case "cm/s^2" -> x = a / 0.0328;
default -> {
return "Err_incorrect_input";
case "ft/s^2" -> {
System.out.println("convert to: (m/s^2 g cm/s^2)");
to = sc.next();
switch (to) {
case "m/s^2" -> x = a / 3.2808;
case "g" -> x = a / 32.174;
case "cm/s^2" -> x = a / 0.0328;
default -> {
return "Err_incorrect_input";
}
}
}
}
case "g" -> {
System.out.println("convert to: (m/s^2 ft/s^2 cm/s^2)");
to = sc.nextLine();
switch (to) {
case "m/s^2" -> x = a * 9.0866;
case "ft/s^2" -> x = a * 32.174;
case "cm/s^2" -> x = a * 980.665;
default -> {
return "Err_incorrect_input";
case "g" -> {
System.out.println("convert to: (m/s^2 ft/s^2 cm/s^2)");
to = sc.next();
switch (to) {
case "m/s^2" -> x = a * 9.0866;
case "ft/s^2" -> x = a * 32.174;
case "cm/s^2" -> x = a * 980.665;
default -> {
return "Err_incorrect_input";
}
}
}
case "cm/s^2" -> {
System.out.println("convert to: (m/s^2 ft/s^2 g)");
to = sc.next();
switch (to) {
case "m/s^2" -> x = a / 100;
case "ft/s^2" -> x = a / 30.48;
case "g" -> x = a / 980.665;
default -> {
return "Err_incorrect_input";
}
}
}
default -> {
return "Err_incorrect_input";
}
}
case "cm/s^2" -> {
System.out.println("convert to: (m/s^2 ft/s^2 g)");
to = sc.nextLine();
switch (to) {
case "m/s^2" -> x = a / 100;
case "ft/s^2" -> x = a / 30.48;
case "g" -> x = a / 980.665;
default -> {
return "Err_incorrect_input";
return "%s %s = %.2f %s".formatted(a, unit, x, to);
}
case "angle" -> {
System.out.println("unit: (rad deg min sec)");
unit = sc.next();
switch (unit) {
case "rad" -> {
System.out.println("convert to: (deg min sec)");
to = sc.next();
switch (to) {
case "deg" -> x = a * 57.2958;
case "min" -> x = a * 3437.7468;
case "sec" -> x = a * 206264.8062;
default -> {
return "Err_incorrect_input";
}
}
}
case "deg" -> {
System.out.println("convert to: (rad min sec)");
to = sc.next();
switch (to) {
case "rad" -> x = a / 57.2958;
case "min" -> x = a * 60;
case "sec" -> x = a * 3600;
default -> {
return "Err_incorrect_input";
}
}
}
case "min" -> {
System.out.println("convert to: (rad deg sec)");
to = sc.next();
switch (to) {
case "rad" -> x = a / 3437.7468;
case "deg" -> x = a / 60;
case "sec" -> x = a * 60;
default -> {
return "Err_incorrect_input";
}
}
}
case "sec" -> {
System.out.println("convert to: (rad deg min)");
to = sc.next();
switch (to) {
case "rad" -> x = a / 206264.8062;
case "deg" -> x = a * 3600;
case "min" -> x = a * 60;
default -> {
return "Err_incorrect_input";
}
}
}
default -> {
return "Err_incorrect_input";
}
}
return "%f %s = %.4f %s".formatted(a, unit, x, to);
}



default: return "Err_incorrect_input";
}
default -> {
return "Err_incorrect_input";
}
}
}
}
}

0 comments on commit 2ae2172

Please sign in to comment.