Class Calculator

java.lang.Object
  |
  +--Calculator

public final class Calculator
extends java.lang.Object

The Calculator class is designed primarily to illustrate how the Math class works. In fact, the only real difference is that the Math clas is part of a package, java.lang, which is automatically imported (since we always at least need to extend Object)


Method Summary
static double absoluteValue(double param)
          the absolute value function for real numbers (decimals)
static int absoluteValue(int param)
          the absolute value function for integers (non-decimals)
static double add(double param1, double param2)
          addition for real numbers (decimals)
static int add(int param1, int param2)
          addition for integers (non-decimals)
static double average(double param1, double param2)
          average taking in real numbers (decimals)
static double average(int param1, int param2)
          average taking in integers (non-decimals)
static double divide(double param1, double param2)
          division for real numbers (decimals)
static int divide(int param1, int param2)
          division for integers (non-decimals)
static boolean even(int param)
          a boolean test of integers (non-decimals)
static int factorial(int param)
          recursive factorial.
static double multiply(double param1, double param2)
          multiplication for real numbers (decimals)
static int multiply(int param1, int param2)
          multiplication for integers (non-decimals)
static boolean odd(int param)
          a boolean test of integers (non-decimals)
static double square(double param)
          the squarring function for real numbers (decimals)
static int square(int param)
          the squarring function for integers (non-decimals)
static double squareRoot(double param)
          the square root function taking in reeal numbers (decimals)
static double squareRoot(int param)
          the square root function taking in integers (non-decimals)
static double subtract(double param1, double param2)
          subtraction for real numbers (decimals)
static int subtract(int param1, int param2)
          subtraction for integers (non-decimals)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

add

public static int add(int param1,
                      int param2)
addition for integers (non-decimals)

Parameters:
param1 - the first addend
param2 - the second addend
Returns:
the sum

add

public static double add(double param1,
                         double param2)
addition for real numbers (decimals)

Parameters:
param1 - the first addend
param2 - the second addend
Returns:
the sum

subtract

public static int subtract(int param1,
                           int param2)
subtraction for integers (non-decimals)

Parameters:
param1 - the first subtraction parameter
param2 - the second subtraction parameter
Returns:
the difference

subtract

public static double subtract(double param1,
                              double param2)
subtraction for real numbers (decimals)

Parameters:
param1 - the first subtraction parameter
param2 - the second subtraction parameter
Returns:
the difference

multiply

public static int multiply(int param1,
                           int param2)
multiplication for integers (non-decimals)

Parameters:
param1 - the first factor
param2 - the second factor
Returns:
the product

multiply

public static double multiply(double param1,
                              double param2)
multiplication for real numbers (decimals)

Parameters:
param1 - the first factor
param2 - the second factor
Returns:
the product

divide

public static int divide(int param1,
                         int param2)
division for integers (non-decimals)

Parameters:
param1 - the numerator
param2 - the denominator
Returns:
the quotient without remainder

divide

public static double divide(double param1,
                            double param2)
division for real numbers (decimals)

Parameters:
param1 - the numerator
param2 - the denominator
Returns:
the quotient

average

public static double average(int param1,
                             int param2)
average taking in integers (non-decimals)

Parameters:
param1 - the first parameter
param2 - the second parameter
Returns:
the exact (decimal) average

average

public static double average(double param1,
                             double param2)
average taking in real numbers (decimals)

Parameters:
param1 - the first parameter
param2 - the second parameter
Returns:
the exact (decimal) average

square

public static int square(int param)
the squarring function for integers (non-decimals)

Parameters:
param - the number to be squarred
Returns:
the square of the number

square

public static double square(double param)
the squarring function for real numbers (decimals)

Parameters:
param - the number to be squarred
Returns:
the square of the number

squareRoot

public static double squareRoot(int param)
the square root function taking in integers (non-decimals)

Parameters:
param - the number to be rooted
Returns:
the exact (decimal) square root of the number

squareRoot

public static double squareRoot(double param)
the square root function taking in reeal numbers (decimals)

Parameters:
param - the number to be rooted
Returns:
the square root of the number

factorial

public static int factorial(int param)
recursive factorial. factorial is defined as the product of all positive numbers from 1 to the argument, inclusively. Factorial of n is sometimes written n!. 0! = 1 by definition. n! is undefined for n < 0 and for non-integers.

Parameters:
param - the parameter
Returns:
the product of all integers from 1 to the parameter inclusively

absoluteValue

public static int absoluteValue(int param)
the absolute value function for integers (non-decimals)

Parameters:
param - the parameter
Returns:
the euclidean distance from the paramter to zero

absoluteValue

public static double absoluteValue(double param)
the absolute value function for real numbers (decimals)

Parameters:
param - the parameter
Returns:
the euclidean distance from the paramter to zero

even

public static boolean even(int param)
a boolean test of integers (non-decimals)

Parameters:
param - the number to test for eveness
Returns:
true when the number is a an exact multiple of 2 and false otherwise

odd

public static boolean odd(int param)
a boolean test of integers (non-decimals)

Parameters:
param - the number to test for oddness
Returns:
false when the number is a an exact multiple of 2 and true otherwise