Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases

Authors: Ian Robinson, Jim Webber, Emil Eifrem

1st Edition

1449356265, 978-1449356262

More Books

Students also viewed these Databases questions

Question

What is the first step in the accounting cycle

Answered: 1 week ago

Question

10. Are you a. a leader? b. a follower? _______

Answered: 1 week ago