implement a whole bunch of simple methods.

MathUtilities.java 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. return (short) (baseValue+difference);
  28. }
  29. /**
  30. * @param baseValue starting value
  31. * @param difference value to add to starting value
  32. * @return sum of `baseValue` and `difference`
  33. */
  34. public Byte add(byte baseValue, byte difference) {
  35. return (byte) (baseValue+difference) ;
  36. }
  37. /**
  38. * @param baseValue starting value
  39. * @param difference value to add to starting value
  40. * @return sum of `baseValue` and `difference`
  41. */
  42. public Float add(float baseValue, float difference) {
  43. return (float) (baseValue+difference);
  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 Double add(double baseValue, double difference) {
  51. return (double) (baseValue+difference);
  52. }
  53. /**
  54. * @param baseValue starting value
  55. * @param difference value to subtract from starting value
  56. * @return difference between `baseValue` and `difference`
  57. */
  58. public Integer subtract(int baseValue, int 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 Long subtract(long baseValue, long 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 Short subtract(short baseValue, short difference) {
  75. return (short) (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 Byte subtract(byte baseValue, byte difference) {
  83. return (byte) (baseValue-difference);
  84. }
  85. /**
  86. * @param baseValue starting value
  87. * @param difference value to subtract from starting value
  88. * @return difference between `baseValue` and `difference`
  89. */
  90. public Float subtract(float baseValue, float difference) {
  91. return (float) (baseValue-difference);
  92. }
  93. /**
  94. * @param baseValue starting value
  95. * @param difference value to subtract from starting value
  96. * @return difference between `baseValue` and `difference`
  97. */
  98. public Double subtract(double baseValue, double difference) {
  99. return (double) (baseValue-difference);
  100. }
  101. /**
  102. * @param dividend value to be divided
  103. * @param divisor value to divide by
  104. * @return division of `dividend` by `divisor
  105. */
  106. public Integer divide(int dividend, int divisor) {
  107. return dividend/divisor;
  108. }
  109. /**
  110. * @param dividend value to be divided
  111. * @param divisor value to divide by
  112. * @return division of `dividend` by `divisor
  113. */
  114. public Long divide(long dividend, long divisor) {
  115. return dividend/divisor;
  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 Short divide(short dividend, short divisor) {
  123. return (short) (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 Byte divide(byte dividend, byte divisor) {
  131. return (byte) (dividend/divisor)
  132. ;
  133. }
  134. /**
  135. * @param dividend value to be divided
  136. * @param divisor value to divide by
  137. * @return division of `dividend` by `divisor
  138. */
  139. public Float divide(float dividend, float divisor) {
  140. return (float) (dividend/divisor);
  141. }
  142. /**
  143. * @param dividend value to be divided
  144. * @param divisor value to divide by
  145. * @return division of `dividend` by `divisor
  146. */
  147. public Double divide(double dividend, double divisor) {
  148. return (double) (dividend/divisor);
  149. }
  150. /**
  151. * @param multiplicand value to be multiplied
  152. * @param multiplier value to multiply by
  153. * @return product of `multiplicand` by `multiplier`
  154. */
  155. public Integer multiply(int multiplicand, int multiplier) {
  156. return multiplicand*multiplier;
  157. }
  158. /**
  159. * @param multiplicand value to be multiplied
  160. * @param multiplier value to multiply by
  161. * @return product of `multiplicand` by `multiplier`
  162. */
  163. public Long multiply(long multiplicand, long multiplier) {
  164. return multiplicand*multiplier;
  165. }
  166. /**
  167. * @param multiplicand value to be multiplied
  168. * @param multiplier value to multiply by
  169. * @return product of `multiplicand` by `multiplier`
  170. */
  171. public Short multiply(short multiplicand, short multiplier) {
  172. return (short) (multiplicand*multiplier);
  173. }
  174. /**
  175. * @param multiplicand value to be multiplied
  176. * @param multiplier value to multiply by
  177. * @return product of `multiplicand` by `multiplier`
  178. */
  179. public Byte multiply(byte multiplicand, byte multiplier) {
  180. return (byte) (multiplicand*multiplier);
  181. }
  182. /**
  183. * @param multiplicand value to be multiplied
  184. * @param multiplier value to multiply by
  185. * @return product of `multiplicand` by `multiplier`
  186. */
  187. public Float multiply(float multiplicand, float multiplier) {
  188. return (float) (multiplicand*multiplier);
  189. }
  190. /**
  191. * @param multiplicand value to be multiplied
  192. * @param multiplier value to multiply by
  193. * @return product of `multiplicand` by `multiplier`
  194. */
  195. public Double multiply(double multiplicand, double multiplier) {
  196. return (double) (multiplicand*multiplier);
  197. }
  198. /**
  199. * @return true
  200. */
  201. public Boolean returnTrue() {
  202. return true;
  203. }
  204. /**
  205. * @return false
  206. */
  207. public Boolean returnFalse() {
  208. return false;
  209. }
  210. }