solves quadratic equations. It demonstrates the use of functions (methods with parameters and return values).
public double toDouble(String s)
Changes a String to a double value. If the String contains a non-numeric
value (or something else fails), the function returns NaN (Not-a-Number).
public boolean bad(double num)
Decides whether a number is NaN (e.g. bad) or normal (okay).
public double root(double num)
Safely calculates the square-root of a number - returns the square-root or
NaN (if num is negative).
Math.sqrt(num)
Calculates the square-root of a number.
Double.parseDouble(s)
Changes a String to a double value.
Math.pow(b,2)
Calculates a power = b^2
Font bigFont = new Font("Arial",0,24);
lTitle.setFont(bigFont)
Changes the Font in the lTitle label to a larger font.
Java includes a variety of standard functions, but the programmer will want to make their own. For example, Double.parseDouble is used so often, that it is useful to "wrap" it inside a user-defined function (e.g. toDouble) to simplify the coding of the rest of the program. The programmer can also add error-handling code, making a "safe" version of a function.
The Math class contains lots of standard functions - absolute value, power, square-root, sin, cos, etc. These are static, so they can be used without instantiating a Math object.
The Double object is not the same as a double variable. The Double object contains a single double value, along with a variety of methods for manipulating double values. Many of these methods are static and can be used without instantiating an object.