MathUtilities.java 1.2KB

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