Class Algebra

java.lang.Object
mathvoyage.algebra.Algebra

public class Algebra extends Object
voyager.Algebra.java
Author:
Adib Sakhawat
  • Method Summary

    Modifier and Type
    Method
    Description
    double
    abs(double number)
    returns the absolute value of a number.
    int
    abs(int number)
    returns the absolute value of a number.
    <T extends Number>
    double
    cubeRoot(T number)
    Calculates the cube root of a number.
    double
    floor(double value)
    Calculates the floor value of a number.
    int
    gcd(int a, int b)
    Calculates the GCD of a number.
    static Algebra
    Returns the singleton instance of this class.
    int
    lcm(int a, int b)
    Calculates LCM of a number.
    <T extends Comparable<T>>
    T
    max(T[] array)
    Returns the maximum of an array of comparable objects.
    <T extends Comparable<T>>
    T
    max(T a, T b)
    Returns the maximum of two comparable objects.
    <T extends Comparable<T>>
    int
    maxIndex(T[] array)
    returns the index of the maximum of an array of comparable objects.
    <T extends Comparable<T>>
    T
    min(T[] array)
    Returns the minimum of an array of comparable objects.
    <T extends Comparable<T>>
    T
    min(T a, T b)
    Returns the minimum of two comparable objects.
    <T extends Comparable<T>>
    int
    minIndex(T[] array)
    returns the index of the minimum of an array of comparable objects.
    <T extends Number>
    double
    nthRoot(T x, int n)
    Finds the nth root of a number.
    <T extends Number>
    double
    pow(T base, int exponent)
    Calculates the power of a number.
    <T extends Number>
    double
    sqrt(T number)
    Calculates the square root of a number.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getInstance

      public static Algebra getInstance()
      Returns the singleton instance of this class.
      Returns:
      The singleton instance
    • abs

      public double abs(double number)
      returns the absolute value of a number.
      Parameters:
      number - The number
      Returns:
      The absolute value
    • abs

      public int abs(int number)
      returns the absolute value of a number.
      Parameters:
      number - The number
      Returns:
      The absolute value
    • min

      public <T extends Comparable<T>> T min(T a, T b)
      Returns the minimum of two comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      a - The first object
      b - The second object
      Returns:
      The minimum of the two objects
    • min

      public <T extends Comparable<T>> T min(T[] array)
      Returns the minimum of an array of comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      array - The array of objects
      Returns:
      The minimum of the array
    • max

      public <T extends Comparable<T>> T max(T a, T b)
      Returns the maximum of two comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      a - The first object
      b - The second object
      Returns:
      The maximum of the two objects
    • max

      public <T extends Comparable<T>> T max(T[] array)
      Returns the maximum of an array of comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      array - The array of objects
      Returns:
      The maximum of the array
    • minIndex

      public <T extends Comparable<T>> int minIndex(T[] array)
      returns the index of the minimum of an array of comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      array - The array of objects
      Returns:
      The index of the minimum of the array
    • maxIndex

      public <T extends Comparable<T>> int maxIndex(T[] array)
      returns the index of the maximum of an array of comparable objects.
      Type Parameters:
      T - the type parameter
      Parameters:
      array - The array of objects
      Returns:
      The index of the maximum of the array
    • pow

      public <T extends Number> double pow(T base, int exponent)
      Calculates the power of a number.
      Type Parameters:
      T - the type parameter
      Parameters:
      base - The base
      exponent - The exponent
      Returns:
      The result
    • sqrt

      public <T extends Number> double sqrt(T number)
      Calculates the square root of a number.
      Type Parameters:
      T - the type parameter
      Parameters:
      number - The number
      Returns:
      The result
    • cubeRoot

      public <T extends Number> double cubeRoot(T number)
      Calculates the cube root of a number.
      Type Parameters:
      T - the type parameter
      Parameters:
      number - The number
      Returns:
      The result
    • nthRoot

      public <T extends Number> double nthRoot(T x, int n)
      Finds the nth root of a number.
      Type Parameters:
      T - the type parameter
      Parameters:
      x - the number which I have to find nth root
      n - the root
      Returns:
      result double
    • gcd

      public int gcd(int a, int b)
      Calculates the GCD of a number.
      Parameters:
      a - The first number
      b - The second number
      Returns:
      The result
    • lcm

      public int lcm(int a, int b)
      Calculates LCM of a number.
      Parameters:
      a - the a
      b - the b
      Returns:
      The result
    • floor

      public double floor(double value)
      Calculates the floor value of a number.
      Parameters:
      value - the value
      Returns:
      double