geofasc.swing.tool
public class Calculator extends Object
Calculator
provides easy access for often used mathematical
operations like computing the square of two numbers or generating a random
number.Constructor and Description |
---|
Calculator()
Creates a new
Calculator . |
Modifier and Type | Method and Description |
---|---|
double |
abs(double num)
See
Math.abs(double) . |
int |
abs(int num)
See
Math.abs(int) . |
int |
intPart(double num)
Computes the integer part of the given double number.
|
double |
power(double base,
double exp)
Returns the value of the first argument raised to the power of the second
argument.
|
int |
power(int base,
int exp)
Returns the value of the first argument raised to the power of the second
argument.
|
double |
random()
Generates a random double number.
|
int |
randomInt()
Generates a random integer.
|
int |
randomInt(int fromNum,
int toNum)
Generates a random integer between the given intervall (including the
left and right bounds of the intervall).
|
int |
round(double num)
See
Math.round(double) . |
double |
sqrt(double num)
See
Math.sqrt(double) . |
double |
square(double num)
Returns the square of the given double number.
|
int |
square(int num)
Returns the square of the given integer number.
|
public double abs(double num)
Math.abs(double)
.public int abs(int num)
Math.abs(int)
.public int intPart(double num)
num
- the double number whose integer part is to computepublic double power(double base, double exp)
base
- the base (has to be non-null)exp
- the exponentpublic int power(int base, int exp)
base
- the base (has to be non-null)exp
- the exponentpublic double random()
public int randomInt()
public int randomInt(int fromNum, int toNum)
fromNum
- the left number of the intervalltoNum
- the right number of the intervallpublic int round(double num)
Math.round(double)
.public double sqrt(double num)
Math.sqrt(double)
.public double square(double num)
num
- the double number to squarepublic int square(int num)
num
- the integer number to square