implement a whole bunch of simple methods.

MathUtilities.java 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * Created by dan on 6/14/17.
  3. */
  4. public class MathUtilities {
  5. /**
  6. * @param baseValue starting value
  7. * @param difference value to add to starting value
  8. * @return sum of `baseValue` and `difference`
  9. */
  10. public Integer add(int baseValue, int difference) {
  11. int add = baseValue + difference;
  12. return add;
  13. }
  14. /**
  15. * @param baseValue starting value
  16. * @param difference value to add to starting value
  17. * @return sum of `baseValue` and `difference`
  18. */
  19. public Long add(long baseValue, long difference) {
  20. long add = baseValue + difference;
  21. return add;
  22. }
  23. /**
  24. * @param baseValue starting value
  25. * @param difference value to add to starting value
  26. * @return sum of `baseValue` and `difference`
  27. */
  28. public Short add(short baseValue, short difference) {
  29. short add = (short) (baseValue + difference);
  30. return add;
  31. }
  32. /**
  33. * @param baseValue starting value
  34. * @param difference value to add to starting value
  35. * @return sum of `baseValue` and `difference`
  36. */
  37. public Byte add(byte baseValue, byte difference) {
  38. byte add = (byte) (baseValue + difference);
  39. return add;
  40. }
  41. /**
  42. * @param baseValue starting value
  43. * @param difference value to add to starting value
  44. * @return sum of `baseValue` and `difference`
  45. */
  46. public Float add(float baseValue, float difference) {
  47. float add = baseValue + difference;
  48. return add;
  49. }
  50. /**
  51. * @param baseValue starting value
  52. * @param difference value to add to starting value
  53. * @return sum of `baseValue` and `difference`
  54. */
  55. public Double add(double baseValue, double difference) {
  56. double add = baseValue + difference;
  57. return add;
  58. }
  59. /**
  60. * @param baseValue starting value
  61. * @param difference value to subtract from starting value
  62. * @return difference between `baseValue` and `difference`
  63. */
  64. public Integer subtract(int baseValue, int difference) {
  65. int subtract = baseValue - difference;
  66. return subtract;
  67. }
  68. /**
  69. * @param baseValue starting value
  70. * @param difference value to subtract from starting value
  71. * @return difference between `baseValue` and `difference`
  72. */
  73. public Long subtract(long baseValue, long difference) {
  74. long subtract = baseValue - difference;
  75. return subtract;
  76. }
  77. /**
  78. * @param baseValue starting value
  79. * @param difference value to subtract from starting value
  80. * @return difference between `baseValue` and `difference`
  81. */
  82. public Short subtract(short baseValue, short difference) {
  83. short subtract = (short) (baseValue - difference);
  84. return subtract;
  85. }
  86. /**
  87. * @param baseValue starting value
  88. * @param difference value to subtract from starting value
  89. * @return difference between `baseValue` and `difference`
  90. */
  91. public Byte subtract(byte baseValue, byte difference) {
  92. byte subtract = (byte) (baseValue - difference);
  93. return subtract;
  94. }
  95. /**
  96. * @param baseValue starting value
  97. * @param difference value to subtract from starting value
  98. * @return difference between `baseValue` and `difference`
  99. */
  100. public Float subtract(float baseValue, float difference) {
  101. float subtract = baseValue - difference;
  102. return subtract;
  103. }
  104. /**
  105. * @param baseValue starting value
  106. * @param difference value to subtract from starting value
  107. * @return difference between `baseValue` and `difference`
  108. */
  109. public Double subtract(double baseValue, double difference) {
  110. double subtract = baseValue - difference;
  111. return subtract;
  112. }
  113. /**
  114. * @param dividend value to be divided
  115. * @param divisor value to divide by
  116. * @return division of `dividend` by `divisor
  117. */
  118. public Integer divide(int dividend, int divisor) {
  119. int divide = dividend / divisor;
  120. return divide;
  121. }
  122. /**
  123. * @param dividend value to be divided
  124. * @param divisor value to divide by
  125. * @return division of `dividend` by `divisor
  126. */
  127. public Long divide(long dividend, long divisor) {
  128. long divide = dividend / divisor;
  129. return divide;
  130. }
  131. /**
  132. * @param dividend value to be divided
  133. * @param divisor value to divide by
  134. * @return division of `dividend` by `divisor
  135. */
  136. public Short divide(short dividend, short divisor) {
  137. short divide = (short) (dividend / divisor);
  138. return divide;
  139. }
  140. /**
  141. * @param dividend value to be divided
  142. * @param divisor value to divide by
  143. * @return division of `dividend` by `divisor
  144. */
  145. public Byte divide(byte dividend, byte divisor) {
  146. byte divide = (byte) (dividend / divisor);
  147. return divide;
  148. }
  149. /**
  150. * @param dividend value to be divided
  151. * @param divisor value to divide by
  152. * @return division of `dividend` by `divisor
  153. */
  154. public Float divide(float dividend, float divisor) {
  155. float divide = dividend / divisor;
  156. return divide;
  157. }
  158. /**
  159. * @param dividend value to be divided
  160. * @param divisor value to divide by
  161. * @return division of `dividend` by `divisor
  162. */
  163. public Double divide(double dividend, double divisor) {
  164. double divide = dividend / divisor;
  165. return divide;
  166. }
  167. /**
  168. * @param multiplicand value to be multiplied
  169. * @param multiplier value to multiply by
  170. * @return product of `multiplicand` by `multiplier`
  171. */
  172. public Integer multiply(int multiplicand, int multiplier) {
  173. int multiply = multiplicand * multiplier;
  174. return multiply;
  175. }
  176. /**
  177. * @param multiplicand value to be multiplied
  178. * @param multiplier value to multiply by
  179. * @return product of `multiplicand` by `multiplier`
  180. */
  181. public Long multiply(long multiplicand, long multiplier) {
  182. long multiply = multiplicand * multiplier;
  183. return multiply;
  184. }
  185. /**
  186. * @param multiplicand value to be multiplied
  187. * @param multiplier value to multiply by
  188. * @return product of `multiplicand` by `multiplier`
  189. */
  190. public Short multiply(short multiplicand, short multiplier) {
  191. short multiply = (short) (multiplicand * multiplier);
  192. return multiply;
  193. }
  194. /**
  195. * @param multiplicand value to be multiplied
  196. * @param multiplier value to multiply by
  197. * @return product of `multiplicand` by `multiplier`
  198. */
  199. public Byte multiply(byte multiplicand, byte multiplier) {
  200. byte multiply = (byte) (multiplicand * multiplier);
  201. return multiply;
  202. }
  203. /**
  204. * @param multiplicand value to be multiplied
  205. * @param multiplier value to multiply by
  206. * @return product of `multiplicand` by `multiplier`
  207. */
  208. public Float multiply(float multiplicand, float multiplier) {
  209. float multiply = multiplicand * multiplier;
  210. return multiply;
  211. }
  212. /**
  213. * @param multiplicand value to be multiplied
  214. * @param multiplier value to multiply by
  215. * @return product of `multiplicand` by `multiplier`
  216. */
  217. public Double multiply(double multiplicand, double multiplier) {
  218. double multiply = multiplicand * multiplier;
  219. return multiply;
  220. }
  221. /**
  222. * @return true
  223. */
  224. public Boolean returnTrue() {
  225. return true;
  226. }
  227. /**
  228. * @return false
  229. */
  230. public Boolean returnFalse() {
  231. return false;
  232. }
  233. }