Write the program described below.
Show answer
Answer
class Highest extends Record
{
int ind;
Highest(int cap)
{
super(cap);
ind = 0;
}
void find()
{
ind = 0;
for (int i = 1; i < size; i++)
{
if (m[i] > m[ind])
ind = i;
}
}
void display()
{
super.display();
find();
System.out.println("Student(s) with the highest mark:");
for (int i = 0; i < size; i++)
{
if (m[i] == m[ind])
System.out.println(n[i] + "\t" + m[i]);
}
}
}Explanation: the parameterised constructor passes cap up to the superclass via super(cap) so that Record's constructor allocates the n[] and m[] arrays of the given size, then initialises ind. find() scans the inherited marks array m[] (indices 0 to size-1) and stores in ind the index of the largest mark. display() first calls super.display() to reuse the superclass's printing of all the array elements, then calls find() and prints the name(s) and mark of the student(s) with the highest mark (handling ties, i.e. more than one student sharing the highest mark). Tested (run for real, with a small Record superclass and main added only for testing) with names/marks {AMIT:78, SUMIT:95, ROHIT:95, MOHIT:60}: the program correctly identified and printed both SUMIT and ROHIT (95) as the students with the highest mark.