Skip to main content
Code Review

Return to Answer

replaced http://codereview.stackexchange.com/ with https://codereview.stackexchange.com/
Source Link

Aside from the use of BigDecimals functions mentioned in JvR's answer JvR's answer, I see one other glaring issue with your code.

Aside from the use of BigDecimals functions mentioned in JvR's answer, I see one other glaring issue with your code.

Aside from the use of BigDecimals functions mentioned in JvR's answer, I see one other glaring issue with your code.

Source Link
Pimgd
  • 22.5k
  • 5
  • 68
  • 144

Aside from the use of BigDecimals functions mentioned in JvR's answer, I see one other glaring issue with your code.

Your indentation is all over the place.

/**
 * Give a new number to this Statistician.
 *
 * @param <CODE>number</CODE> the new number that is being given the this
 * Statistician
 * <dt><b>Postcondition:</b><dd>
 * The specified number has been given to this Statistician and it will be
 * included in any subsequent statistics.
 *
 */
public void nextNumber(double number) {
 length++;
 sum += number;
 last = number;
 if (length == 1) {
 max = number;
 min = number;
 } 
 else {
 if (number > max) {
 max = number;
 }
 }
 if (number < min) {
 min = number;
 }
}

I strongly suggest you find and use the auto-indent functions of your IDE.

As a example, here's how the code should look:

/**
 * Give a new number to this Statistician.
 *
 * @param <CODE>number</CODE> the new number that is being given the this
 * Statistician
 * <dt><b>Postcondition:</b><dd>
 * The specified number has been given to this Statistician and it will be
 * included in any subsequent statistics.
 *
 */
public void nextNumber(double number) {
 length++;
 sum += number;
 last = number;
 if (length == 1) {
 max = number;
 min = number;
 } else {
 if (number > max) {
 max = number;
 }
 }
 if (number < min) {
 min = number;
 }
}

Proper indentation makes it easier to find optimizations too. You could convert

 else {
 if (number > max) {
 max = number;
 }
 }

into

 else if (number > max) {
 max = number;
 }

without any risk. This makes the code even shorter, without reducing meaning. It effectively becomes easier to understand.

lang-java

AltStyle によって変換されたページ (->オリジナル) /