MathUtilities.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import java.util.*;
  2. import java.text.DecimalFormat;
  3. public class MathUtilities{
  4. /**
  5. * Add two number together
  6. * @param num1 first number
  7. * @param num2 second number
  8. * @return the sum of the two numbers
  9. */
  10. public int add(int num1, int num2){
  11. int solution = num1 + num2;
  12. return solution;
  13. }
  14. /**
  15. * Add two number together
  16. * @param num1 first number
  17. * @param num2 second number
  18. * @return the sum of the two numbers
  19. */
  20. public double add(double num1, double num2){
  21. double solution = num1 + num2;
  22. return solution;
  23. }
  24. /**
  25. * Get half the value of the number
  26. * @param number the number given
  27. * @return the half of the number in double
  28. */
  29. public double half(int number) {
  30. double ohokay = number / 2;
  31. DecimalFormat solution = new DecimalFormat(".#");
  32. String theone = solution.format(ohokay);
  33. double answer = (double) ohokay;
  34. return answer;
  35. }
  36. /**
  37. * Determine if the number is odd
  38. * @param number the number given
  39. * @return true if the number is odd, false if it is even
  40. */
  41. public boolean isOdd(int number){
  42. if ((number % 2) != 0) {
  43. return true;} else { return false;}
  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 solution = number * number;
  52. return solution;
  53. }
  54. }