Question
Assume that two-dimensional arrays are used to store information about families and the individual age of each member. Each row represents a family, and each
Assume that two-dimensional arrays are used to store information about families and the individual age of each member. Each row represents a family, and each column represents a different member. All families have the same number of members. The two-dimensional array named individualAges contains the individuals' numerical ages (integers such as 5, 23, 59, 83, etc.). The other array is ageCategory and contains the corresponding age category as a String (i.e. "C", "T", "Y", "A", and "S"). Note, the categories and age ranges may vary. For this example, we will use the following scale. However, any range and any categories may be used. Do not assume all ages 61 and over will have a category of S for Senior Citizen. Child (C): 012 Teenager (T): 1319 Young Adult (Y): 2030 Adult(A): 3160 Senior Citizen(S): 61 and up For example, if individualAges[0][0] contains 17, then the contents of ageCategory[0][0] will contain the corresponding letter for the age category. In this case, the age category is T because the statistician is using the above age scale. public class AgeRecords { private int[][] individualAges; private String[][] ageCategory; // constructors not shown // postcondition: returns 1.0 if category does not appear in ageCategory // otherwise, returns the average of all individualAges with corresponding // ageCategory values that are equal to the parameter category. public double categoryAverage(String category) { } // other methods not shown } Write the method categoryAverage. This method returns a double representing the average (arithmetic mean) of the average ages that correspond to a given age category, such that categoryAverage returns 1.0 if none of the individual ages corresponds to the given category. For example, given the following two-dimensional arrays: individualAges: 5 43 13 16 28 43 15 35 10 21 ageCategory: C A T T Y A T A C Y The method call categoryAverage("T") would return the number 14.67, which is the average of the three ages that correspond to the "T" category for teenagers. The method call categoryAverage("S") would return 1.0 because none of the ageCategory elements are equal to S. Complete the method categoryAverage. Be sure to include the method header.
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