12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import java.util.Scanner;
  2. import java.lang.*;
  3. public class DisplayVal{
  4. private double value = 0;
  5. private String numSys = "Decimal";
  6. private String disVal = "0";
  7. Scanner stdin = new Scanner(System.in);
  8. NumSystemsConverter conv = new NumSystemsConverter();
  9. //Scanner stdin = new Scanner(System.in);
  10. public double getValue(){
  11. return this.value;
  12. }
  13. public void setValue(double num){
  14. this.value = num;
  15. }
  16. public void setNumSys(){
  17. System.out.println("Select number system to use: (Enter # 1-4)");
  18. System.out.println("(1)Decimal");
  19. System.out.println("(2)Binary");
  20. System.out.println("(3)Octal");
  21. System.out.println("(4)Hexadecimal");
  22. System.out.print("> ");
  23. int num = stdin.nextInt();
  24. switch(num){
  25. case 1:
  26. this.numSys = "Decimal";
  27. break;
  28. case 2:
  29. this.numSys = "Binary";
  30. break;
  31. case 3:
  32. this.numSys = "Octal";
  33. break;
  34. case 4:
  35. this.numSys = "Hexadecimal";
  36. break;
  37. }
  38. this.setDisVal(conv.updateDisplayNumber(this.value,num)); //not working
  39. }
  40. public void toggleNumSys(){
  41. if(this.numSys == "Decimal"){
  42. this.numSys = "Binary";
  43. } else if(this.numSys == "Binary"){
  44. this.numSys = "Octal";
  45. } else if(this.numSys == "Octal"){
  46. this.numSys = "Hexadecimal";
  47. } else if(this.numSys == "Hexadecimal"){
  48. this.numSys = "Decimal";
  49. } else {
  50. this.numSys = "Decimal";
  51. }
  52. }
  53. public String getNumSys(){
  54. return this.numSys;
  55. }
  56. public void setDisVal(String value){
  57. this.disVal = value;
  58. }
  59. public String valToString(double num){
  60. String displayStr = new String();
  61. displayStr += "" + num;
  62. return displayStr;
  63. }
  64. }