MathUtilities.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. public class MathUtilities{
  2. /**
  3. * Add two number together
  4. * @param num1 first number
  5. * @param num2 second number
  6. * @return the sum of the two numbers
  7. */
  8. public int add(int num1, int num2){
  9. return num1 + num2;
  10. }
  11. /**
  12. * Add two number together
  13. * @param num1 first number
  14. * @param num2 second number
  15. * @return the sum of the two numbers
  16. */
  17. public double add(double num1, double num2){
  18. return num1 + num2;
  19. }
  20. /**
  21. * Get half the value of the number
  22. * @param number the number given
  23. * @return the half of the number in double
  24. */
  25. public double half(int number) {
  26. return (double)number/2;
  27. }
  28. /**
  29. * Determine if the number is odd
  30. * @param number the number given
  31. * @return true if the number is odd, false if it is even
  32. */
  33. public boolean isOdd(int number){
  34. boolean answer = true;
  35. if(number % 2 == 0){
  36. answer = false;
  37. }else if(number % 2 != 0){
  38. answer = true;
  39. }
  40. return answer;
  41. }
  42. /**
  43. * Multiply the number by itself
  44. * @param number the number given
  45. * @return the result of the number multiply by itself
  46. */
  47. public int square(int number) {
  48. return number * number;
  49. }
  50. }