Advertisement
Guest User

Kappa

a guest
Mar 26th, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class SeatingChart
  4. {
  5. private Student[][] seats;
  6.  
  7. public SeatingChart (List<Student> studentList, int rows, int cols)
  8. {
  9. int x = 0;
  10. seats = new Student[rows][cols];
  11. for(int i = 0; i < cols; i++)
  12. {
  13. for(int j = 0; j < rows; j++)
  14. {
  15. if(!studentList.isEmpty())
  16. {
  17. seats[j][i] = studentList.get(x);
  18. studentList.remove(x);
  19. }
  20. }
  21. }
  22. }
  23.  
  24. public int removeAbsentStudents (int allowedAbsences)
  25. {
  26. int x = 0;
  27. for(int i = 0;i < seats.length ;i++)
  28. {
  29. for(int k = 0;k < seats[0].length; k++)
  30. {
  31. if (seats[i][k].getAbsenceCount() >= allowedAbsences)
  32. {
  33. seats[i][k] = null;
  34. x++;
  35. }
  36. }
  37. }
  38. return x;
  39. }
  40.  
  41. // For Testing Purposes
  42. public String toString()
  43. {
  44. String result = "";
  45. for (int r = 0; r < seats.length; r++) {
  46. result += "Row #" + r + "\n";
  47.  
  48. for (int c = 0; c < seats[r].length; c++) {
  49. if (seats[r][c] != null) {
  50. result += "\tSeat #" + c + "\n";
  51. result += "\t" + seats[r][c].getName() + ": " + seats[r][c].getAbsenceCount() + " absences\n";
  52. } else
  53. result += "\tempty\n";
  54. }
  55.  
  56. result += "==========================\n";
  57. }
  58.  
  59. return result;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement