Functions.java 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /**
  2. * Write a description of class Functions here.
  3. *
  4. * @author (your name)
  5. * @version (a version number or a date)
  6. */
  7. import java.util.Scanner;
  8. import java.lang.Math;
  9. import java.lang.Math;
  10. import java.math.BigDecimal;
  11. public class Functions
  12. {
  13. double first;
  14. double second;
  15. static double mem;
  16. static double value;
  17. public static int display;
  18. public static String show = "Decimal";
  19. static Scanner scan = new Scanner(System.in);
  20. public void functions() {
  21. }
  22. public static double add(double first, double second){
  23. double value = first + second;
  24. return value;
  25. }
  26. public static double subtract(double first, double second){
  27. double value = first - second;
  28. return value;
  29. }
  30. public static double multiply(double first, double second){
  31. double value = first * second;
  32. return value;
  33. }
  34. public static double divide(double top, double bot){
  35. if (bot != 0){
  36. return (top / bot);
  37. } else {
  38. System.out.println("ERROR! ERROR! Try using some numbers that work!");
  39. }
  40. return top / bot;
  41. }
  42. public static double square(double input){
  43. double value = Math.pow(input, 2);
  44. return value;
  45. }
  46. public static double squareRoot(double input){
  47. return Math.sqrt(input);
  48. }
  49. public static double exponent(double first, double exp){
  50. double value = Math.pow(first, exp);
  51. return value;
  52. }
  53. public static double inverse(double input){
  54. double value = 1/(input);
  55. return value;
  56. }
  57. public static double invertSign(double input){
  58. double value = -(input);
  59. return value;
  60. }
  61. public static String radDeg = scan.nextLine();
  62. public static double sin(double input){
  63. System.out.println("radians or degrees?");
  64. String radDeg = scan.nextLine();
  65. if(radDeg.equalsIgnoreCase("degrees")){
  66. input = Math.toRadians(input);
  67. }
  68. else if(radDeg.equalsIgnoreCase("radians")){
  69. input = input;
  70. }
  71. value = Math.sin(input);
  72. return value;
  73. }
  74. public static double cos(double input){
  75. System.out.println("radians or degrees?");
  76. String radDeg = scan.nextLine();
  77. if(radDeg.equalsIgnoreCase("degrees")){
  78. input = Math.toRadians(input);
  79. }
  80. else if(radDeg.equalsIgnoreCase("radians")){
  81. input = input;
  82. }
  83. value = Math.cos(input);
  84. return value;
  85. }
  86. public static double tan(double input){
  87. System.out.println("radians or degrees?");
  88. String radDeg = scan.nextLine();
  89. if(radDeg.equalsIgnoreCase("degrees")){
  90. input = Math.toRadians(input);
  91. }
  92. else if(!radDeg.equalsIgnoreCase("radians")){
  93. input = input;
  94. }
  95. value = Math.tan(input);
  96. return value;
  97. }
  98. public static double arcsin(double input){
  99. double answer = 0;
  100. System.out.println("radians or degrees?");
  101. String radDeg = scan.nextLine();
  102. if(radDeg.equalsIgnoreCase("degrees")){
  103. answer = (float)Math.toDegrees(Math.asin(input));
  104. }
  105. else if(radDeg.equalsIgnoreCase("radians")){
  106. answer = Math.asin(input);
  107. }
  108. value = answer;
  109. return value;
  110. }
  111. public static double arccos(double input){
  112. double answer = 0;
  113. System.out.println("radians or degrees?");
  114. String radDeg = scan.nextLine();
  115. if(radDeg.equalsIgnoreCase("degrees")){
  116. answer = Math.toDegrees(Math.acos(input));
  117. }
  118. else if(radDeg.equalsIgnoreCase("radians")){
  119. answer = Math.acos(input);
  120. }
  121. value = answer;
  122. return value;
  123. }
  124. public static double arctan(double input){
  125. double answer = 0;
  126. System.out.println("radians or degrees?");
  127. String radDeg = scan.nextLine();
  128. if(radDeg.equalsIgnoreCase("degrees")){
  129. answer = Math.toDegrees(Math.atan(input));
  130. }
  131. else if(radDeg.equalsIgnoreCase("radians")){
  132. answer = Math.atan(input);
  133. }
  134. value = answer;
  135. return value;
  136. }
  137. public static double csc(double input){
  138. System.out.println("radians or degrees?");
  139. String radDeg = scan.nextLine();
  140. if(radDeg.equalsIgnoreCase("degrees")){
  141. input = Math.toRadians(input);
  142. }
  143. else if(radDeg.equalsIgnoreCase("radians")){
  144. input = input;
  145. }
  146. value = 1/(Math.sin(input));
  147. return value;
  148. }
  149. public static double sec(double input){
  150. System.out.println("radians or degrees?");
  151. String radDeg = scan.nextLine();
  152. if(radDeg.equalsIgnoreCase("degrees")){
  153. input = Math.toRadians(input);
  154. }
  155. else if(radDeg.equalsIgnoreCase("radians")){
  156. input = input;
  157. }
  158. value = 1/(Math.cos(input));
  159. return value;
  160. }
  161. public static double cot(double input){
  162. System.out.println("radians or degrees?");
  163. String radDeg = scan.nextLine();
  164. if(radDeg.equalsIgnoreCase("degrees")){
  165. input = Math.toRadians(input);
  166. }
  167. else if(radDeg.equalsIgnoreCase("radians")){
  168. input = input;
  169. }
  170. value = 1/(Math.tan(input));
  171. return value;
  172. }
  173. public static double ln(double input){
  174. return Math.log(input);
  175. }
  176. public static double inverseLn(double input){
  177. return Math.exp(Math.log(input));
  178. }
  179. public static double memPlus(double value) {
  180. mem += value;
  181. return mem;
  182. }
  183. public static double memClear(double value) {
  184. mem = 0;
  185. return mem;
  186. }
  187. public static double recall() {
  188. return mem;
  189. }
  190. }