Menu

Java Question Assume Two Dimensional Arrays Used Store Information Families Individual Age Q43808501

JAVA QUESTION

Assume that two-dimensional arrays are used to store informationabout families and the individual age of each member. Each rowrepresents a family, and each column represents a different member.All families have the same number of members.

The two-dimensional array named individualAges contains theindividuals’ numerical ages (integers such as 5, 23, 59, 83, etc.).The other array is ageCategory and contains the corresponding agecategory as a String (i.e. “C”, “T”, “Y”, “A”, and “S”).

Note, the categories and age ranges may vary. For this example, wewill use the following scale. However, any range and any categoriesmay be used. Do not assume all ages 61 and over will have acategory of S for Senior Citizen.

      Child (C): 0–12
      Teenager (T): 13–19
      Young Adult (Y): 20–30
      Adult(A): 31–60
      Senior Citizen(S): 61 andup

For example, if individualAges[0][0] contains 17, then the contentsof ageCategory[0][0] will contain the corresponding letter for theage category. In this case, the age category is T because thestatistician is using the above age scale.

public class AgeRecords
{
      private int[][]individualAges;
      private String[][]ageCategory;

      // constructors not shown

      // postcondition: returns −1.0if category does not appear in ageCategory
      // otherwise, returns theaverage of all individualAges with corresponding
      // ageCategory values that areequal to the parameter category.
      public doublecategoryAverage(String category)
      {

      }

      // other methods notshown

}

Write the method categoryAverage. This method returns a doublerepresenting the average (arithmetic mean) of the average ages thatcorrespond to a given age category, such that categoryAveragereturns −1.0 if none of the individual ages corresponds to thegiven category.

For example, given the following two-dimensional arrays:
individualAges:       5 43 13 1628
                     4315 35 10 21
ageCategory:         CA T T Y
                     AT 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 noneof the ageCategory elements are equal to S.

Complete the method categoryAverage. Be sure to include the methodheader.

EDIT:

THE 2D ARRAY SHOULD BE 5 UNITS LONG AND 2 UNITS TALL

FOR EXAMPLE :

C A T T Y
A T A C Y

AND ANOTHER EXAMPLE OF ARRAY DIMENSION:

5 43 13 16 28

43 15 35 10 21

Expert Answer


Answer to JAVA QUESTION Assume that two-dimensional arrays are used to store information about families and the individual age of …

OR