Conversion.java 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Write a description of class Conversion here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.Scanner;
  8. public class Conversion
  9. {
  10. // instance variables - replace the example below with your own
  11. public static int display;
  12. public static String show = "Decimal";
  13. static String answer = "";
  14. static Scanner scan = new Scanner(System.in);
  15. public static double switchDisplay(double value){
  16. System.out.println("choose from: binary, octal, decimal, and hexadecimal \n"
  17. +"to convert answer");
  18. String input = scan.nextLine();
  19. int[] displayOptions= new int[]{2,8,10,16};
  20. if(input.equalsIgnoreCase("binary")){
  21. display = displayOptions[0];
  22. System.out.println("binary");
  23. //answer = (double)Integer.toBinaryString((Functions.value));
  24. answer = Long.toBinaryString(Double.doubleToRawLongBits(Functions.value));
  25. }
  26. else if(input.equalsIgnoreCase("octal")){
  27. display = displayOptions[1];
  28. System.out.println("octal");
  29. Long.toOctalString(Double.doubleToRawLongBits(Functions.value));
  30. }
  31. else if(input.equalsIgnoreCase("decimal")){
  32. display = displayOptions[2];
  33. System.out.println("answer already in decimal mode");
  34. }
  35. else if(input.equalsIgnoreCase("hexadecimal")){
  36. display = displayOptions[3];
  37. System.out.println("hexadecimal selected");
  38. answer = Double.toHexString(Functions.value);
  39. }
  40. else{
  41. System.out.print("Invalid choice try again");
  42. display = display;
  43. }
  44. System.out.println(answer);
  45. return 0;
  46. }
  47. }