Skip to content

Commit 94b6789

Browse files
Change To Average.java
1 parent 13262f5 commit 94b6789

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/main/java/com/thealgorithms/maths/Average.java

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
package com.thealgorithms.maths;
22

33
/**
4-
* Utility class for calculating the average of numeric arrays.
4+
* A utility class for computing the average of numeric arrays.
5+
* This class provides static methods to calculate the average of arrays
6+
* of both {@code double} and {@code int} values.
57
*/
68
public final class Average {
79

8-
// Private constructor to prevent instantiation
10+
// Prevent instantiation of this utility class
911
private Average() {
12+
throw new UnsupportedOperationException("This is a utility class and cannot be instantiated.");
1013
}
1114

1215
/**
13-
* Calculates the average of a double array.
16+
* Computes the average of a {@code double} array.
1417
*
15-
* @param numbers an array of doubles
16-
* @return the mean of the given numbers
17-
* @throws IllegalArgumentException if the array is null or empty
18+
* @param numbers an array of {@code double} values
19+
* @return the average of the given numbers
20+
* @throws IllegalArgumentException if the input array is {@code null} or empty
1821
*/
19-
public static double calculateAverage(double[] numbers) {
22+
public static double computeAverage(double[] numbers) {
2023
if (numbers == null || numbers.length == 0) {
21-
throw new IllegalArgumentException("Array cannot be null or empty.");
24+
throw new IllegalArgumentException("Array must not be null or empty.");
2225
}
2326
double sum = 0;
2427
for (double number : numbers) {
@@ -28,15 +31,15 @@ public static double calculateAverage(double[] numbers) {
2831
}
2932

3033
/**
31-
* Calculates the average of an int array.
34+
* Computes the average of an {@code int} array.
3235
*
33-
* @param numbers an array of integers
34-
* @return the mean of the given numbers
35-
* @throws IllegalArgumentException if the array is null or empty
36+
* @param numbers an array of {@code int} values
37+
* @return the average of the given numbers
38+
* @throws IllegalArgumentException if the input array is {@code null} or empty
3639
*/
37-
public static int calculateAverage(int[] numbers) {
40+
public static int computeAverage(int[] numbers) {
3841
if (numbers == null || numbers.length == 0) {
39-
throw new IllegalArgumentException("Array cannot be null or empty.");
42+
throw new IllegalArgumentException("Array must not be null or empty.");
4043
}
4144
long sum = 0;
4245
for (int number : numbers) {

0 commit comments

Comments
 (0)