MathUtilities.java 6.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 x = baseValue+ difference;
  28. return (short)x;
  29. }
  30. /**
  31. * @param baseValue starting value
  32. * @param difference value to add to starting value
  33. * @return sum of `baseValue` and `difference`
  34. */
  35. public Byte add(byte baseValue, byte difference) {
  36. int x = baseValue +difference;
  37. return (byte) x;
  38. }
  39. /**
  40. * @param baseValue starting value
  41. * @param difference value to add to starting value
  42. * @return sum of `baseValue` and `difference`
  43. */
  44. public Float add(float baseValue, float difference) {
  45. return baseValue + difference;
  46. }
  47. /**
  48. * @param baseValue starting value
  49. * @param difference value to add to starting value
  50. * @return sum of `baseValue` and `difference`
  51. */
  52. public Double add(double baseValue, double difference) {
  53. return baseValue + difference;
  54. }
  55. /**
  56. * @param baseValue starting value
  57. * @param difference value to subtract from starting value
  58. * @return difference between `baseValue` and `difference`
  59. */
  60. public Integer subtract(int baseValue, int difference) {
  61. return baseValue - difference;
  62. }
  63. /**
  64. * @param baseValue starting value
  65. * @param difference value to subtract from starting value
  66. * @return difference between `baseValue` and `difference`
  67. */
  68. public Long subtract(long baseValue, long difference) {
  69. double x = baseValue - difference;
  70. return (long) x;
  71. }
  72. /**
  73. * @param baseValue starting value
  74. * @param difference value to subtract from starting value
  75. * @return difference between `baseValue` and `difference`
  76. */
  77. public Short subtract(short baseValue, short difference) {
  78. int x = baseValue -difference;
  79. return (short) x;
  80. }
  81. /**
  82. * @param baseValue starting value
  83. * @param difference value to subtract from starting value
  84. * @return difference between `baseValue` and `difference`
  85. */
  86. public Byte subtract(byte baseValue, byte difference) {
  87. int x = baseValue -difference;
  88. return (byte) x;
  89. }
  90. /**
  91. * @param baseValue starting value
  92. * @param difference value to subtract from starting value
  93. * @return difference between `baseValue` and `difference`
  94. */
  95. public Float subtract(float baseValue, float difference) {
  96. return baseValue- difference;
  97. }
  98. /**
  99. * @param baseValue starting value
  100. * @param difference value to subtract from starting value
  101. * @return difference between `baseValue` and `difference`
  102. */
  103. public Double subtract(double baseValue, double difference) {
  104. return baseValue - difference;
  105. }
  106. /**
  107. * @param dividend value to be divided
  108. * @param divisor value to divide by
  109. * @return division of `dividend` by `divisor
  110. */
  111. public Integer divide(int dividend, int divisor) {
  112. return dividend/divisor;
  113. }
  114. /**
  115. * @param dividend value to be divided
  116. * @param divisor value to divide by
  117. * @return division of `dividend` by `divisor
  118. */
  119. public Long divide(long dividend, long divisor) {
  120. return dividend/divisor;
  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 Short divide(short dividend, short divisor) {
  128. int x =dividend /divisor;
  129. return (short) x;
  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 Byte divide(byte dividend, byte divisor) {
  137. int x =dividend /divisor;
  138. return (byte) x;
  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 Float divide(float dividend, float divisor) {
  146. return dividend/ divisor;
  147. }
  148. /**
  149. * @param dividend value to be divided
  150. * @param divisor value to divide by
  151. * @return division of `dividend` by `divisor
  152. */
  153. public Double divide(double dividend, double divisor) {
  154. return dividend/divisor;
  155. }
  156. /**
  157. * @param multiplicand value to be multiplied
  158. * @param multiplier value to multiply by
  159. * @return product of `multiplicand` by `multiplier`
  160. */
  161. public Integer multiply(int multiplicand, int multiplier) {
  162. return multiplicand*multiplier;
  163. }
  164. /**
  165. * @param multiplicand value to be multiplied
  166. * @param multiplier value to multiply by
  167. * @return product of `multiplicand` by `multiplier`
  168. */
  169. public Long multiply(long multiplicand, long multiplier) {
  170. double x =multiplicand * multiplier;
  171. return (long) x;
  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 Short multiply(short multiplicand, short multiplier) {
  179. int x =multiplicand * multiplier;
  180. return (short) x;
  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 Byte multiply(byte multiplicand, byte multiplier) {
  188. int x =multiplicand * multiplier;
  189. return (byte) x;
  190. }
  191. /**
  192. * @param multiplicand value to be multiplied
  193. * @param multiplier value to multiply by
  194. * @return product of `multiplicand` by `multiplier`
  195. */
  196. public Float multiply(float multiplicand, float multiplier) {
  197. return multiplicand*multiplier;
  198. }
  199. /**
  200. * @param multiplicand value to be multiplied
  201. * @param multiplier value to multiply by
  202. * @return product of `multiplicand` by `multiplier`
  203. */
  204. public Double multiply(double multiplicand, double multiplier) {
  205. return multiplicand * multiplier ;
  206. }
  207. /**
  208. * @return true
  209. */
  210. public Boolean returnTrue() {
  211. return true;
  212. }
  213. /**
  214. * @return false
  215. */
  216. public Boolean returnFalse() {
  217. return false;
  218. }
  219. }