Question
Write a program that reads a list of 25 values from the user. Put the values in an array. The program should read the array
Write a program that reads a list of 25 values from the user. Put the values in an array. The program should read the array and then calculate and display the average of the even input values and the average of the odd input values. (Hint: You can use Mod to determine if a number is even or odd). We just did this problem in the last lab but this time you must add the values to an array first.
You should design and code a class and a tester. In the class, you will have three instance variables, 1) an array to hold the numbers, 2) a double to hold the odd average and 3) a double to hold the even average. The constructor should accept as input the array from the tester class and assign it to the instant variable; it should also assign 0 to the even and odd average variables. You should then have a method that will read the array and then calculate the average of the even input values and the average of the odd input values. (Hint: You can use % (mod) to determine if a number is even or odd). Your program will need a getOddAverage and a getEvenAverage method.
The tester class will ask the user to input 10 numbers. It will then create an object passing the filled array to the class. The tester should then call each of the methods that calculate the averages. You will then need to print the even and odd average.
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