Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: replaced more ? with pi symbol.

...

In this compliant solution, a constant PI is declared and initialized to 3.14. Thereafter, it is referenced in the code whenever the value of ? of π is needed.

Code Block
bgColor#ccccff
private static final double PI = 3.14;

double area(double radius) {
  return 4.0 * PI * radius * radius;
}

double volume(double radius) {
  return 4.0/3.0 * PI * radius * radius * radius;
}

double greatCircleCircumference(double radius) {
  return 2 * PI * radius;
}

This technique reduces clutter and promotes maintainability. If a more precise approximation of the value of ? of π is required, the programmer can simply redefine the constant.

...