‹ Back to the paper
[Object as an Argument] A sports academy wants to conduct a friendly match between two teams with…
[Object as an Argument]
A sports academy wants to conduct a friendly match between two teams with maximum fifteen players. A class Sports contains three data members, to store the name of the team with ‘n’ number of players and a one-dimensional array to store height of each player. Design a class Sports to compare average height of both the teams. The details of the members of the class are given below:
Class Name : Sports
Data Members / Instance Variables:
height[] : to store the height of each player
name : to store the name of the team
n : to store total number of players
Member methods:
Sports() : default constructor
Sports(int n, String name) : to initialize the number of players and name of the team
void fillHeight() : to enter the height of all the players
double averageHeight() : to calculate average height of the team
String compare(Sports s1, Sports s2) : to compare average height of both the teams and return the name of the team with the higher average height
void display(String msg) : to display the name of the team with the higher average height stored in msg. If both the teams have the same average height, then msg should be “Both teams have the same average height.”
Specify the class Sports giving the details of constructors, void fillHeight( ), double averageHeight( ), String compare(Sports, Sports), void display(String). Write the main( ) method to call methods defined in an appropriate manner.
Answer
No answer yet.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 74.