ScientificFeatures.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /**
  2. * Write a description of class ScientificFeatures here.
  3. */
  4. public class ScientificFeatures
  5. {
  6. Console console = new Console();
  7. // instance variables - replace the example below with your own
  8. public int Mode = 10;
  9. public String trigOptions= "degrees";
  10. public double M;
  11. public String displayMode = "Decimal";
  12. /**
  13. * Constructor for objects of class ScientificFeatures
  14. */
  15. public ScientificFeatures(Console c)
  16. {
  17. console = c;
  18. }
  19. /**
  20. * A method
  21. */
  22. public int switchDisplayMode(String value){
  23. int[] modeOptions= new int[]{2,8,10,16};
  24. if(value.equals("")){
  25. if(Mode == 2){
  26. Mode = modeOptions[1];
  27. displayMode = "Octal";
  28. }
  29. else if(Mode == 8){
  30. Mode = modeOptions[2];
  31. displayMode = "Decimal";
  32. }
  33. else if(Mode == 10){
  34. Mode = modeOptions[3];
  35. displayMode = "Hexadecimal";
  36. }
  37. else if(Mode == 16){
  38. Mode = modeOptions[0];
  39. displayMode = "Binary";
  40. }
  41. }
  42. else if(value.equals("decimal")){
  43. Mode = modeOptions[2];
  44. displayMode = "Decimal";
  45. }
  46. else if(value.equals("binary")){
  47. Mode = modeOptions[0];
  48. displayMode = "Binary";
  49. }
  50. else if(value.equals("octal")){
  51. Mode = modeOptions[1];
  52. displayMode = "Octal";
  53. }
  54. else if(value.equals("hexadecimal")){
  55. Mode = modeOptions[3];
  56. displayMode = "Hexadecimal";
  57. }
  58. else{
  59. System.out.print("Invalid choice try again");
  60. Mode = Mode;
  61. }
  62. return Mode;
  63. }
  64. public String switchUnitsMode(String value){
  65. if(value.equals("")){
  66. if(trigOptions.equals("degrees")){
  67. trigOptions = "radians";
  68. }
  69. else if(trigOptions.equals("radians")){
  70. trigOptions = "degrees";
  71. }
  72. }
  73. else if(value.equals("degrees")){
  74. trigOptions = "degrees";
  75. }
  76. else if(value.equals("radians")){
  77. trigOptions = "radians";
  78. }
  79. else{
  80. System.out.print("Invalid choice try again");
  81. trigOptions= trigOptions;
  82. }
  83. return trigOptions;
  84. }
  85. public double sine(double value){
  86. if (trigOptions.equals("degrees")){
  87. value = Math.toRadians(value);
  88. }
  89. return console.changeCurrentValue(Math.sin(value));
  90. }
  91. public double cosine(double value){
  92. if (trigOptions.equals("degrees")){
  93. if (value == 90){
  94. return console.changeCurrentValue(0);
  95. }
  96. value = Math.toRadians(value);
  97. }
  98. return console.changeCurrentValue(Math.cos(value));
  99. }
  100. public double tangent(double value){
  101. if (trigOptions.equals("degrees")){
  102. value = Math.toRadians(value);
  103. }
  104. return console.changeCurrentValue(Math.tan(value));
  105. }
  106. public double invSine(double value){
  107. if (trigOptions.equals("degrees")){
  108. value = Math.toRadians(value);
  109. }
  110. return console.changeCurrentValue(Math.asin(value));
  111. }
  112. public double invCosine(double value){
  113. value = Math.toRadians(value);
  114. if (trigOptions.equals("degrees")){
  115. value = Math.toRadians(value);
  116. }
  117. return console.changeCurrentValue(Math.acos(value));
  118. }
  119. public double invTangent(double value){
  120. value = Math.toRadians(value);
  121. if (trigOptions.equals("degrees")){
  122. value = Math.toRadians(value);
  123. }
  124. return console.changeCurrentValue(Math.atan(value));
  125. }
  126. }