123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import java.util.Scanner;
  2. public class Units
  3. {
  4. Scanner units = new Scanner(System.in);
  5. public double choice (double num) {
  6. boolean isValid = false;
  7. int modechoice = 0;
  8. double result = 0;
  9. while(!isValid){
  10. System.out.println("\n-------------------------------------------------");
  11. System.out.println(num);
  12. System.out.println("-------------------------------------------------");
  13. System.out.println("Select which unit you would like to convert to (enter #1 or #2)");
  14. System.out.println("(1) Degrees");
  15. System.out.println("(2) Radians");
  16. System.out.println("--------------------------------------------");
  17. System.out.print("> ");
  18. modechoice = units.nextInt();
  19. switch(modechoice){
  20. case 1: result = this.degrees(num);
  21. isValid = true;
  22. break;
  23. case 2: result = this.radians(num);
  24. isValid = true;
  25. break; }
  26. }
  27. return result;
  28. }
  29. public double degrees (double num) {
  30. System.out.println("Please enter your value for degree conversion");
  31. boolean isValid = false;
  32. double output = 0;
  33. double input = units.nextInt();
  34. if (!Double.isNaN(num)) {
  35. System.out.println("Calculating degrees of " + input);
  36. num = Math.toDegrees(input);
  37. System.out.println(num);}
  38. else {
  39. System.out.println("Please enter your value");
  40. }
  41. return num;
  42. };
  43. public double radians (double num) {
  44. System.out.println("Please enter your value for radian conversion");
  45. boolean isValid = true;
  46. double output = 0;
  47. double input = units.nextInt();
  48. if (!Double.isNaN(num)) {
  49. System.out.println("Calculating radians of " + input);
  50. num = Math.toRadians(input);
  51. System.out.println(num);}
  52. else {
  53. System.out.println("Please enter your value");
  54. }
  55. return num;
  56. }
  57. }