CoreFunctions.java 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. public class CoreFunctions
  2. {
  3. public static boolean decMode = true;
  4. public static boolean hexMode = false;
  5. public static boolean binMode = false;
  6. public static boolean octMode = false;
  7. public static String hexOut;
  8. public static String binOut;
  9. public static String octOut;
  10. public static double add(double display, double entered) {
  11. if(decMode == true){
  12. System.out.println(display + entered);
  13. return display = display + entered;
  14. }
  15. else if(hexMode == true) {
  16. hexOut = Double.toHexString(display + entered);
  17. System.out.println(hexOut);
  18. return display = display + entered;
  19. }
  20. else if(binMode == true) {
  21. binOut = Long.toBinaryString(Double.doubleToRawLongBits((display + entered)));
  22. System.out.println(binOut);
  23. return display = display + entered;
  24. }
  25. else {
  26. octOut = Long.toOctalString(Double.doubleToRawLongBits((display + entered)));
  27. System.out.println(octOut);
  28. return display = display + entered;
  29. }
  30. }
  31. public static double subtract(double display, double entered) {
  32. if(decMode == true){
  33. System.out.println(display - entered);
  34. return display = display - entered;
  35. }
  36. else if(hexMode == true) {
  37. hexOut = Double.toHexString(display - entered);
  38. System.out.println(hexOut);
  39. return display = display - entered;
  40. }
  41. else if(binMode == true) {
  42. binOut = Long.toBinaryString(Double.doubleToRawLongBits((display - entered)));
  43. System.out.println(binOut);
  44. return display = display - entered;
  45. }
  46. else {
  47. octOut = Long.toOctalString(Double.doubleToRawLongBits((display - entered)));
  48. System.out.println(octOut);
  49. return display = display - entered;
  50. }
  51. }
  52. public static double multiply(double display, double entered) {
  53. if(decMode == true){
  54. System.out.println(display * entered);
  55. return display = display * entered;
  56. }
  57. else if(hexMode == true) {
  58. hexOut = Double.toHexString(display * entered);
  59. System.out.println(hexOut);
  60. return display = display * entered;
  61. }
  62. else if(binMode == true) {
  63. binOut = Long.toBinaryString(Double.doubleToRawLongBits((display * entered)));
  64. System.out.println(binOut);
  65. return display = display * entered;
  66. }
  67. else {
  68. octOut = Long.toOctalString(Double.doubleToRawLongBits((display * entered)));
  69. System.out.println(octOut);
  70. return display = display * entered;
  71. }
  72. }
  73. public static double divide(double display, double entered) {
  74. if(entered != 0){
  75. if(decMode == true){
  76. System.out.println(display / entered);
  77. return display = display / entered;
  78. }
  79. else if(hexMode == true) {
  80. hexOut = Double.toHexString(display / entered);
  81. System.out.println(hexOut);
  82. return display = display / entered;
  83. }
  84. else if(binMode == true) {
  85. binOut = Long.toBinaryString(Double.doubleToRawLongBits((display / entered)));
  86. System.out.println(binOut);
  87. return display = display / entered;
  88. }
  89. else {
  90. octOut = Long.toOctalString(Double.doubleToRawLongBits((display / entered)));
  91. System.out.println(octOut);
  92. return display = display / entered;
  93. }
  94. }else {
  95. System.out.println("Err");
  96. return display = 0;
  97. }
  98. }
  99. public static double exp(double display, double entered) {
  100. if(decMode == true){
  101. System.out.println( Math.pow(display,entered));
  102. return display = Math.pow(display,entered);
  103. }
  104. else if(hexMode == true) {
  105. hexOut = Double.toHexString(Math.pow(display,entered));
  106. System.out.println(hexOut);
  107. return display = Math.pow(display,entered);
  108. }
  109. else if(binMode == true) {
  110. binOut = Long.toBinaryString(Double.doubleToRawLongBits(Math.pow(display,entered)));
  111. System.out.println(binOut);
  112. return display = Math.pow(display,entered);
  113. }
  114. else {
  115. octOut = Long.toOctalString(Double.doubleToRawLongBits(Math.pow(display,entered)));
  116. System.out.println(octOut);
  117. return display = Math.pow(display,entered);
  118. }
  119. }
  120. }