CoreFeatures.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /**
  2. * Write a description of class CoreFeatures here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. public class CoreFeatures extends MainApplication {
  8. // instance variables - replace the example below with your own
  9. private double x;
  10. private double addedNumbers;
  11. //addition
  12. private double subtractedNumbers;
  13. //subtraction
  14. private double multipliedNumbers;
  15. //multiplication
  16. private double dividedNumbers;
  17. //divide
  18. private double squaredNumber;
  19. //square
  20. private double squareRoot;
  21. //square root
  22. private boolean calcRunning;
  23. //calculator status
  24. private double switchedNumber;
  25. //changing the sign of a number
  26. private double inversedNumber;
  27. //inversing a number
  28. private boolean clearCalculator;
  29. //clear button
  30. //private double memory;
  31. //number to be stored
  32. //public double m;
  33. //memory button
  34. /**
  35. * Constructor for objects of class CoreFeatures
  36. */
  37. public CoreFeatures(){
  38. // initialise instance variables
  39. x = 0;
  40. }
  41. public double addNumbers(double adding1, double adding2){
  42. addedNumbers = adding1 + adding2;
  43. return addedNumbers;}
  44. public double subtractNumbers(double subtracting1, double subtracting2){
  45. subtractedNumbers = subtracting1 - subtracting2;
  46. return subtractedNumbers;}
  47. public double multiplyNumbers(double multiplying1, double multiplying2){
  48. multipliedNumbers = multiplying1 * multiplying2;
  49. return multipliedNumbers;}
  50. public double divideNumbers(double dividing1, double dividing2){
  51. if (dividing2 == 0){
  52. System.out.println("**ERROR** CANNOT DIVIDE BY ZERO.");
  53. Console.result = 0;} else {
  54. dividedNumbers = dividing1 / dividing2;
  55. return dividedNumbers;}
  56. /*double userCorrectedInput = Console.getDoubleInput("**Err** CANNOT DIVIDE BY ZERO. Please clear the calculator.");
  57. return userCorrectedInput;*/
  58. /*dividedNumbers = dividing1 / dividing2;
  59. return dividedNumbers;*/
  60. return dividedNumbers;}
  61. public double squareNumber(double squaring){
  62. squaredNumber = squaring * squaring;
  63. return squaredNumber;}
  64. public double squareRoot(double squareRooting){
  65. squareRoot = squareRoot(squareRooting);
  66. return squareRoot;}
  67. public double switchSign(double switchingSign){
  68. switchedNumber = switchingSign * -1;
  69. return switchedNumber;
  70. }
  71. public double inverseNumber(double inversing){
  72. inversedNumber = 1/inversing;
  73. return inversedNumber;
  74. }
  75. public boolean clearCalculator(){
  76. clearCalculator = true;
  77. Console.result = 0;
  78. return clearCalculator;
  79. }
  80. public boolean calcRunning(){
  81. calcRunning = false;
  82. return calcRunning;
  83. }
  84. /*public double memoryStore(){
  85. memory = Console.result;
  86. if (memory == Console.result){
  87. m = memory;
  88. }
  89. return memory;
  90. }
  91. */
  92. }