implement a whole bunch of simple methods.

MathUtilities.java 7.3KB

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