Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Code: Classromm.java package edu.csc413.collections; import java.util.*; public class Classroom { // Constants. You can refer to these anywhere within the Classroom class. private static final
Code:
Classromm.java
package edu.csc413.collections; import java.util.*; public class Classroom { // Constants. You can refer to these anywhere within the Classroom class. private static final int CLASS_CAPACITY = 15; private static final int WAIT_LIST_CAPACITY = 5; // Instance variables. private HashMap registeredStudents; private HashSet enrolledIds; private Queue waitlistIds; public Classroom() { // TODO: Implement. Initialize any instance variables here. } public void registerStudent(Student student) { // TODO: Implement. The student should be registered, but not enrolled in the class or added to the waitlist. } public void enrollStudent(int id) { // TODO: Implement. The student with the provided ID should be added the enrolled students set if there is // capacity. If there is not, but there is capacity in the waitlist, the student should be added to that // instead. If there is no capacity in the enrollment set or the waitlist, the request can be ignored. } public void dropStudent(int id) { // TODO: Implement. Attempt to remove the student with the provided ID from the enrolled students set. If the // student was removed, backfill the enrolled students set with a student from the waitlist. } public ArrayList getEnrolledStudents() { // TODO: Implement. Return the names of all students that are enrolled in an ArrayList. return new ArrayList(); } public ArrayList getWaitlistedStudents() { // TODO: Implement. Return the names of all of the students that are in the waitlist in an ArrayList. // They should be in the same order that they are in the waitlist. return new ArrayList(); } public static void main(String[] args) { Classroom classroom = new Classroom(); if (NAMES.length != IDS.length) { throw new RuntimeException("Oops! The NAMES and IDS arrays don't match. Did they get modified?"); } // Register all of the students defined by NAMES and IDS below. for (int i = 0; iStudent.java
package edu.csc413.collections; /** * Represents a student that can be registered for, enrolled in, and dropped from the class. For the sake of simplicity, * a student consists of just their name and ID. */ public class Student { private final String name; private final int id; public Student(String name, int id) { this.name = name; this.id = id; } public String getName() { return name; } public int getId() { return id; } }Modified Version Make a modification to your implementation of the getWaitlistedStudents method so that it returns the list of student names in reverse order. To get full credit, you must use the Stack data structure. Detailed Requirements Summary of requirements: 1. Implement the correct Classroom behavior detailed below in Base Version. 2. Base Version implementation is committed and submitted to the GitHub repository. 3. Implement the modification detailed below in Modified Version. 4. Modified Version implementation is committed and submitted to the GitHub repository, separate from the commit in requirement #2. 5. README.md file in the project is filled out. Base Version You are provided with a partially implemented Java file, Classroom.java, and a completed Java file, Student.java. Your task is to implement all of the methods in Classroom class. You will need to provide implementation code in every section of the file where you see the following comment: // TODO: Implement. The Classroom manages a roster of registered students. Students can be enrolled, waitlisted, or neither. When a student is registered, the Classroom object should track that student's full information, so that it can be retrieved later with just the student ID. However, registering a student does not enroll them in the class or add them to the waitlist. When a student is enrolled, they are placed in a collection tracking the IDs of students enrolled in the class. The student can only be enrolled if there is spare capacity. If not, there should be an attempt to place them in the waitlist. When a student is placed in the waitlist, they go to the back of the waitlist, behind any students that are already there. The student can only be waitlisted if there is spare capacity. If not, the student's enrollment request is ignored. When a student is dropped from the course, their ID is removed from the collection of enrolled students. If that frees up space in the class, the first student in line in the waitlist should automatically be enrolled. If a student is in the waitlist and is dropped from the course, that request is ignored. The Classroom can provide lists of student names when requested for those that are enrolled and those that are waitlisted. The set of enrolled student IDs and the waitlist queue should not be modified in any way when these names are requested. You can use a for each loop to process each element in a collection: for (int id: waitlistIds) { // Use id here. } You must use the collections provided for you in the list of instance variables (registered Students, enrolledIds, and waitlistIds). You cannot change any of the method signatures (i.e. method names, parameter lists, and return types). If you've implemented the base version correctly, the names of enrolled students printed should include everything from "Alice" through Queen Latifa," except for Eli and Klay." However, the order they're printed will not be in alphabetical order. The waitlist should have "Rupert," "Serena," "Tobias," and "Eli." Modified Version Make a modification to your implementation of the getWaitlistedStudents method so that it returns the list of student names in reverse order. To get full credit, you must use the Stack data structure. Detailed Requirements Summary of requirements: 1. Implement the correct Classroom behavior detailed below in Base Version. 2. Base Version implementation is committed and submitted to the GitHub repository. 3. Implement the modification detailed below in Modified Version. 4. Modified Version implementation is committed and submitted to the GitHub repository, separate from the commit in requirement #2. 5. README.md file in the project is filled out. Base Version You are provided with a partially implemented Java file, Classroom.java, and a completed Java file, Student.java. Your task is to implement all of the methods in Classroom class. You will need to provide implementation code in every section of the file where you see the following comment: // TODO: Implement. The Classroom manages a roster of registered students. Students can be enrolled, waitlisted, or neither. When a student is registered, the Classroom object should track that student's full information, so that it can be retrieved later with just the student ID. However, registering a student does not enroll them in the class or add them to the waitlist. When a student is enrolled, they are placed in a collection tracking the IDs of students enrolled in the class. The student can only be enrolled if there is spare capacity. If not, there should be an attempt to place them in the waitlist. When a student is placed in the waitlist, they go to the back of the waitlist, behind any students that are already there. The student can only be waitlisted if there is spare capacity. If not, the student's enrollment request is ignored. When a student is dropped from the course, their ID is removed from the collection of enrolled students. If that frees up space in the class, the first student in line in the waitlist should automatically be enrolled. If a student is in the waitlist and is dropped from the course, that request is ignored. The Classroom can provide lists of student names when requested for those that are enrolled and those that are waitlisted. The set of enrolled student IDs and the waitlist queue should not be modified in any way when these names are requested. You can use a for each loop to process each element in a collection: for (int id: waitlistIds) { // Use id here. } You must use the collections provided for you in the list of instance variables (registered Students, enrolledIds, and waitlistIds). You cannot change any of the method signatures (i.e. method names, parameter lists, and return types). If you've implemented the base version correctly, the names of enrolled students printed should include everything from "Alice" through Queen Latifa," except for Eli and Klay." However, the order they're printed will not be in alphabetical order. The waitlist should have "Rupert," "Serena," "Tobias," and "Eli
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started