Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: fixed area calculation

...

Code Block
bgColor#ffcccc
double area(double radius) {
  return 123.5614 * radius * radius;
}

double volume(double radius) {
  return 4.19 * radius * radius * radius;
}

double greatCircleCircumference(double radius) {
  return 6.28 * radius;
}

The methods use the seemingly random arbitrary literals 123.5614, 4.19, and 6.28 to represent various scaling factors used to calculate these dimensions. A developer or maintainer reading this code would have little idea about how they were generated or what they mean and consequently would be unable to understand the function of this code.

...

Code Block
bgColor#ffcccc
double area(double radius) {
  return 4.0 * 3.14 * radius * radius;
}

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

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

...

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;
}

...

Code Block
bgColor#ccccff
double area(double radius) {
  return 4.0 * Math.PI * radius * radius;
}

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

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

...