Seatingchart AP Computer Science Haas

Seatingchart AP Computer Science Haas

<p>0184dbc3ed59f486ac4ce3ace54e7560.docx AP Computer Science --- Haas</p><p>A student in a school is represented by the following. public class Student { private String name; private int absenceCount;</p><p> public Student (String nm, int count) { name = nm; absenceCount = count; }</p><p>/** Returns the name of this Student. */ public String getName() { return name; }</p><p>/** Returns the number of times a Student has missed class. */ public int getAbsenceCount() { return absenceCount; }</p><p> public String toString() { return name + " " + absenceCount; } }</p><p>The class SeatingChart, uses a two-dimensional array to represent the seating arrangement of students in a classroom. a) Write the constructor for the SeatingChart class. The constructor initializes the seats instance variable to a two-dimensional array with the given number of rows and columns. The students in studentList, are placed into the seating chart in column major order. Empty seats in the seating chart are represented by null.</p><p>A SeatingChart object with the call new SeatingChart(roster, 3, 4) would create the following.</p><p> b) Write the removeAbsentStudents method, which removes students who have more than a given number of absences from the seating chart and returns the number of students that were removed. When a student is removed from the seating chart a null is placed in that entry.</p><p>The chart below shows the chart after the call chart.removeAbsentStudents(4)</p><p> c) Complete the toString method to return the seating chart 2-Dimentional array as a grid.</p><p>Below is the incomplete SeatingChart class. /********************************************************* * Below is the expected output: * * [Karen, 3][Lester, 1][Glen, 2][Danny, 3] * [Liz, 1][Henry, 5][Fran, 6][null] * [Paul, 4][Renee, 9][David, 1][null] * * Removed = 3 * [Karen, 3][Lester, 1][Glen, 2][Danny, 3] * [Liz, 1][null][null][null] * [Paul, 4][null][David, 1][null] **********************************************************/ import java.util.Arrays; import java.util.List; public class SeatingChart { /** seats[r][c] represents the Student in row r and column c in the classroom. */ private Student[][] seats;</p><p>/** Creates a seating chart with the given number of rows and columns from the students in * studentList. Empty seats in the seating chart are represented by null. * @param rows the number of rows of seats in the classroom * @param cols the number of columns of seats in the classroom * Precondition: rows > 0; cols > 0; * rows * cols >= studentList.size() * Postcondition: * - Students appear in the seating chart in the same order as they appear * in studentList, starting at seats[0][0]. * - seats is filled column by column from studentList, followed by any * empty seats (represented by null). * - studentList is unchanged. */ public SeatingChart(List<Student> studentList, int rows, int cols) { /********************** Part (a) *********************/ }</p><p>/** Removes students who have more than a given number of absences from the * seating chart, replacing those entries in the seating chart with null * and returns the number of students removed. * @param allowedAbsences an integer >= 0 * @return number of students removed from seats * Postcondition: * - All students with allowedAbsences or fewer are in their original positions in seat * - No student in seats has more than allowedAbsences absences. * - Entries without students contain null. */ public int removeAbsentStudents(int allowedAbsences) { /********************** Part (b) *********************/ }</p><p>/** complete the toString method to return the seating chart * 2-Dimentional array as a grid. */ public String toString() { /********************** Part (c) *********************/ }</p><p>/********************** Tester Is Complete *********************/ public static void main(String[] args) { Student[] students = { new Student("Karen", 3), new Student("Liz", 1), new Student("Paul", 4), new Student("Lester", 1), new Student("Henry", 5), new Student("Renee", 9), new Student("Glen", 2), new Student("Fran", 6), new Student("David", 1), new Student("Danny", 3)};</p><p>List<Student> roster = Arrays.asList(students); SeatingChart chart = new SeatingChart(roster, 3, 4); System.out.println(chart); System.out.println("Removed = " + chart.removeAbsentStudents(4)); System.out.println(chart); } }</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us