Write a class named ArrayOperations with the following static methods : • getTot
ID: 3762137 • Letter: W
Question
Write a class named ArrayOperations with the following static methods :
• getTotal: This method should accept a one-dimensional array as its argument
and return the total of the values in this array .
• getAverage: This method should accept a one-dimensional array as its argument
and return the average of the values in the array .
• getHighest: This method should accept a one-dimensional array as its argument
and return the highest value in the array .
• getLowest: This method should accept a one-dimensional array as its argument
and return the lowest value in the array .
Write overloaded versions of all of these methods that work with int , float,
double , and long arrays .
Demonstrate the class in a complete program with test data stored in the following
arrays :
{1, 2, 3, 4, 5, 6, 7}
{9.56, 2.39, 3.86, 4.1, 5.34, 1.45, 6.02, 7.35}
{5.2f, 4.5f, 1.3f, 19.2f}
{9048L, 20345L, 7000000L, 2304563L, 3013543L}
For each array , have your program print the results of each of the methods
above (in the order in which the methods are mentioned). Print each number
on a separate line.
Help!! It is the last program of the semester! Please and thank you! xoxo
Explanation / Answer
int getTotal(int a[]){
return a.length();
}
int getAverage(int a[]){
int sum = 0;
for(int i = 0; i < getTotal(a); i++)
sum += a[i];
return sum/getTotal(a);
}
int getHighest(int a[]){
int max = Integer.MIN;
for(int i = 0; i < getTotal(a); i++)
if( a[i] > max )
max = a[i];
return max;
}
int getLowest(int a[]){
int max = Integer.MAX;
for(int i = 0; i < getTotal(a); i++)
if( a[i] < min )
min = a[i];
return min;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.