Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The following program AverageTest calculates and prints the average of all elements of an int array. Write a generic version of findAverage(... ) method so
The following program AverageTest calculates and prints the average of all elements of an int array. Write a generic version of findAverage(... ) method so that the arguments could be of any type rather than restricted to int type. Write the necessary additional codes in the main() method to test the generic version of findAverage (...) method.
class AverageTest
{
public double findAverage( int [ ] sales)
{ int numSales = 0; double total = 0.0; // Calculate the total sales. for (int i = 0; i < 6; i++) total += sales[ i]; return total/6;
} };
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started