CoreFeatures.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 {
  8. public double add(double x) {
  9. double y = Console.getDoubleInput();
  10. return x + y;
  11. }
  12. public double subtract(double x) {
  13. double y = Console.getDoubleInput();
  14. return x - y;
  15. }
  16. public double multiply(double x) {
  17. double y = Console.getDoubleInput();
  18. return x * y;
  19. }
  20. public double divide(double x) {
  21. double y = Console.getDoubleInput();
  22. if (y == 0){
  23. this.error();
  24. return 0;
  25. }
  26. return x / y;
  27. }
  28. public double square(double x) {
  29. return Math.pow(x,2);
  30. }
  31. public double sqrt(double x) {
  32. if (x < 0){
  33. this.error();
  34. return 0;
  35. }
  36. return Math.pow(x,0.5);
  37. }
  38. public double exp(double x) {
  39. double y = Console.getDoubleInput();
  40. return Math.pow(x,y);
  41. }
  42. public double invert(double x) {
  43. if (x == 0){
  44. this.error();
  45. return 0;
  46. }
  47. return 1 / x;
  48. }
  49. public double flip(double x) {
  50. return -1 * x;
  51. }
  52. public void error(){
  53. while (true){
  54. Console.println("Err");
  55. String command = Console.getStringInput();
  56. if (command.equalsIgnoreCase("clear")){
  57. return;
  58. }
  59. }
  60. }
  61. }