MathUtilities.java 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. int result = num1+num2;
  10. return result;
  11. }
  12. /**
  13. * Add two number together
  14. * @param num1 first number
  15. * @param num2 second number
  16. * @return the sum of the two numbers
  17. */
  18. public double add(double num1, double num2){
  19. double result = num1+num2;
  20. return result;
  21. }
  22. /**
  23. * Get half the value of the number
  24. * @param number the number given
  25. * @return the half of the number in double
  26. */
  27. public double half(int number) {
  28. double result = number/2.0;
  29. return result;
  30. }
  31. /**
  32. * Determine if the number is odd
  33. * @param number the number given
  34. * @return true if the number is odd, false if it is even
  35. */
  36. public boolean isOdd(int number){
  37. boolean result;
  38. if (number%2 == 1){
  39. result = true;
  40. } else {
  41. result = false;
  42. }
  43. return result;
  44. }
  45. /**
  46. * Multiply the number by itself
  47. * @param number the number given
  48. * @return the result of the number multiply by itself
  49. */
  50. public int square(int number) {
  51. int result = number*number;
  52. return result;
  53. }
  54. }