Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class SeatingChart
- {
- private Student[][] seats;
- public SeatingChart (List<Student> studentList, int rows, int cols)
- {
- int x = 0;
- seats = new Student[rows][cols];
- for(int i = 0; i < cols; i++)
- {
- for(int j = 0; j < rows; j++)
- {
- if(!studentList.isEmpty())
- {
- seats[j][i] = studentList.get(x);
- studentList.remove(x);
- }
- }
- }
- }
- public int removeAbsentStudents (int allowedAbsences)
- {
- int x = 0;
- for(int i = 0;i < seats.length ;i++)
- {
- for(int k = 0;k < seats[0].length; k++)
- {
- if (seats[i][k].getAbsenceCount() >= allowedAbsences)
- {
- seats[i][k] = null;
- x++;
- }
- }
- }
- return x;
- }
- // For Testing Purposes
- public String toString()
- {
- String result = "";
- for (int r = 0; r < seats.length; r++) {
- result += "Row #" + r + "\n";
- for (int c = 0; c < seats[r].length; c++) {
- if (seats[r][c] != null) {
- result += "\tSeat #" + c + "\n";
- result += "\t" + seats[r][c].getName() + ": " + seats[r][c].getAbsenceCount() + " absences\n";
- } else
- result += "\tempty\n";
- }
- result += "==========================\n";
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement