calculatorCoreFunctions.java 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /**
  2. * Write a description of class calculatorCoreFunctions here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.lang.*;
  8. import java.util.*;
  9. public class calculatorCoreFunctions
  10. {
  11. // instance variables - replace the example below with your own
  12. /**
  13. * Write a description of class calculatorCoreFunctions here.
  14. *
  15. * @author (your name)
  16. * @version (a version number or a date)
  17. */
  18. public calculatorCoreFunctions()
  19. {
  20. // initialise instance variables
  21. double x = 0;
  22. double y = 0;
  23. }
  24. /**
  25. * An example of a method - replace this comment with your own
  26. *
  27. * @param y a sample parameter for a method
  28. * @return the sum of x and y
  29. */
  30. public double add(double x, double y)
  31. {
  32. // put your code here
  33. return x + y;
  34. }
  35. public double subtract(double x, double y)
  36. {
  37. return x - y;
  38. }
  39. public double multiply(double x, double y)
  40. {
  41. return x * y;
  42. }
  43. public double divide(double x, double y)
  44. {
  45. if (y == 0)
  46. {
  47. System.out.println("Invalid input");
  48. return 0;
  49. }
  50. return x / y;
  51. }
  52. public double sqrt(double x)
  53. {
  54. return Math.sqrt(x);
  55. }
  56. public double exponent(double x, double y)
  57. {
  58. return Math.pow(x, y);
  59. }
  60. public double inverse(double x)
  61. {
  62. if (x ==0){
  63. return 0;
  64. }
  65. return 1 / x;
  66. }
  67. }