Seating Charts 2 Download

Christina Cacioppo

arraylists, 2d arrays, for loops, if statements Student approved


Introduction

Now that the nearby school can make seating charts again – thanks to you! – the teachers have asked for a new feature: they'd like to remove students who've too many absences.


Task

Write the removeAbsentStudents() method.

It should remove students with more than a given number of absences from the seating chart, replacing him or her will null.


Starter code

class SeatingChart{
	private Student[][] seats;

	/* @ param	studentList – list of students in the class
	 * @ param	rows – number of rows in the classroom
	 * @ param  cols – number of columns in the classroom
	 * @ consturcts – a seatching chart that places the students in seats
	 */
	public SeatingChart(List studentList, int rows, int cols){
		seats = new Student[cols][rows];
		int studentIndex = 0;
		for(int c = 0; c < cols; c++){
		    for(int r = 0; r < rows; r++){
		        if(studentIndex < studentList.size()){
		            seats[c][r] = studentList.get(studentIndex);
		            studentIndex++;
		        }
		    }
		}
	}

	/* @ param	allowedAbsences – an integer >= 0
	 * @ return	the number of students removed from seats
	 */
	public int removeAbsentStudents(int allowedAbsences){
		// Ensures that SeatingChart seats only contains students with
		// fewer than allowedAbsences absences.
	}
}

class Student{
	private String name;
	private int absences;

	// Constructor – creates a Student object
	public Student(String studentName){
		name = studentName;
	}

	public String toString(){
		return "[Name: " + name + ", absences: " + absences + "]";
	}

	public String getName(){
		return name;
	}

	public int getAbsenceCount(){
		return absences;
	}
}

Expected output

If our SeatingChart looks like this:
"Jessie"
3
"Nitya"
0
"Aidan"
1
"Helena"
2
"Jonathan"
1
"Robert"
7
"Hannah"
6
"Serena"
4
"Sierra"
5
"Duncan"
3
nullnull
It should look like this after we've removed students with more than 4 absences:
"Jessie"
3
"Nitya"
0
"Aidan"
1
"Helena"
2
"Jonathan"
1
null
null"Serena"
4
null"Duncan"
3
nullnull

Useful tools to solve the problem