4. This question involves managing a classroom seating chart represented by a two-dimensional array of Student objects. The seating chart tracks student attendance, where each Student object maintains a record of their total absences. You will write a method in the SeatingChart class to analyze attendance patterns across the classroom.
public class Student
{
/** Returns the number of times this student has been absent. */
public int getAbsenceCount()
{ /* implementation not shown */ }
// There may be instance variables, constructors, and methods that are not shown.
}public class SeatingChart
{
/** The two-dimensional array of student objects representing the seating chart. */
private Student[][] seats;
/**
* Returns the index of the column with the fewest total absences.
* If there is a tie, returns the lowest index.
* Precondition: seats contains at least one row and one column.
* seats contains no null references.
*/
public int columnWithFewestAbsences()
{ /* to be implemented */ }
// There may be instance variables, constructors, and methods that are not shown.
}When an element of the two-dimensional array seats is accessed, the first index is used to specify the row and the second index is used to specify the column.
Write the columnWithFewestAbsences method, which identifies the column in the seating chart with the lowest total number of absences among all students in that column. The method should traverse the 2D array to calculate the total absences for each column and return the index of the column with the minimum total. If multiple columns have the same minimum total, return the smallest index among them.
Suppose seats has the following contents, where each cell shows the Student name and their absence count in parentheses:
Row | 0 | 1 | 2 |
|---|---|---|---|
0 | Alex (2) | Ben (0) | Cathy (5) |
1 | Dana (3) | Eva (1) | Fred (0) |
2 | Gina (1) | Hank (4) | Iris (2) |
Call: columnWithFewestAbsences()
Expected Return: should return 1
Explanation: Column 0 total: 2+3+1 = 6. Column 1 total: 0+1+4 = 5. Column 2 total: 5+0+2 = 7. The minimum total is 5, which corresponds to column index 1.
Write the columnWithFewestAbsences method below.
/**
* Returns the index of the column with the fewest total absences.
* If there is a tie, returns the lowest index.
* Precondition: seats contains at least one row and one column.
* seats contains no null references.
*/
public int columnWithFewestAbsences()