Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with methods 1. enterClassroom, 4. insertMusicalChairs, 5. moveStudentFromChairsToLine and 6. insertByHeight. This is mainly about linked lists. Note that the method 4.
I need help with methods 1. enterClassroom, 4. insertMusicalChairs, 5. moveStudentFromChairsToLine and 6. insertByHeight.
This is mainly about linked lists.
Note that the method "4." takes students from studentsSitting array and place them into circular linked list (musicalChairs). Then, removes the student from the array.
note: (.next in the SNode class is private and cannot be used to implement the code)
The boilerplate code is:
Overview In this assignment you will simulate activities in a kindergarten classroom. You will simulate the students standing in a line, the students on their seats, and the students playing musical chairs. The assignment uses: - a Singly Linked List to simulate student standing in a line. - a 2D array to simulate students at their seats. - a Circular Linked List to simulate students sitting on chairs to play the musical chairs game. A U array simulates students at their seats A Circular Linked List simulates students sitting on chairs to play the musical chairs standing on a line game Implementation Overview of files provided - Student class which holds a student's information. - SNode class represents the node object to be used in the linked structures. It contains a reference to a Student object and a reference to the next node in the list. - Classroom class holds all of the methods to be written and that will be tested when running the game. Edit the empty methods with you solution, but DO NOT edit the provided ones or the methods signatures of any method. This is the file you submit. - Driver class, which is used to test your methods interactively. The classroom state will be printed after every method is used. Feel free to edit this file, as it is provided only to help you test your code. It is not submitted and it is not used to grade your code. - StdRandom class contains the StdRandom.uniform (n) method that you will use in the method that plays the musical chairs game. - Stdln and StdOut, which are used by the driver. Do not edit these classes.. - Multiple text files. Feel free to edit them or even make new ones to help test your code. They are not submitted. - Files containing student information. - Files containing seat location in the classroom. Implementation Overview of files provided - Student class which holds a student's information. - SNode class represents the node object to be used in the linked structures. It contains a reference to a Student object and a reference to the next node in the list. - Classroom class holds all of the methods to be written and that will be tested when running the game. Edit the empty methods with you solution, but DO NOT edit the provided ones or the methods signatures of any method. This is the file you submit. - Driver class, which is used to test your methods interactively. The classroom state will be printed after every method is used. Feel free to edit this file, as it is provided only to help you test your code. It is not submitted and it is not used to grade your code. - StdRandom class contains the StdRandom.uniform( n method that you will use in the method that plays the musical chairs game. - Stdln and StdOut, which are used by the driver. Do not edit these classes.. - Multiple text files. Feel free to edit them or even make new ones to help test your code. They are not submitted. - Files containing student information. Files containing seat availability in the classroom. Classroom.java - DO NOT add new import statements. - DO NOT change any of the method's signatures. - You are encouraged to write helper methods as you see fit. Just make sure that they are private. The class contains: - studentinLine which refers to the first student in the singly linked list - musicalChairs which refers to the LAST student in the circularly linked list when the game is being played - seatingAvailability which is a 2D boolean array that shows which seats are available for students to seat at - studentsSitting which is a 2D Student array that contains the students when they are sitting - NOTE: seatingAvailability and studentsSitting are parallel arrays meaning that seatingAvailability[i][] also refers to the same seat in studentsSitting[i][]] - provided methods that are used by the driver and empty methods you are expected to write your code in - the printClassroom() function can be used to show the state of the classroom (eg. the states of students in line, seating, and musical chairs) at any time in your code - DO NOT add new import statements. - DO NOT change any of the method's signatures. - You are encouraged to write helper methods as you see fit. Just make sure that they are private. The class contains: - studentlnLine which refers to the first student in the singly linked list. - musicalChairs which refers to the LAST student in the circularly linked list when the game is being played. - seatingLocation which is a 2D boolean array that shows which seats exist for students to seat at. - students Sitting which is a 2D Student array that contains the students when they are sitting. - NOTE: seatingLocation and studentsSitting are parallel arrays meaning that seatingLocation[i][i] also refers to the same seat in students Sitting[i][i] - provided methods that are used by the driver and empty methods you are expected to write your code in. - the printClassroom() function can be used to show the state of the classroom (eg. the states of students in line, seating, and musical chairs) at any time in your code. The input file has Students in reverse alphabetical order; so at the end of this method the list will have all students in alphabetical order. DO NOT implement a sorting algorithm, there is no need. - Submit Classroom.java with this method completed under Early Submission to receive extra credit. This is the expected output for students 1 in Students in Line: M. Brow N. Dyer P. Ferg D. Harb M. Hawk C. Heat J. Keer G. Mata . MCLa M. Modi D. Mont P. Reis W. Ryde N. Schn S. Sink F. Wolf Sitting Students: EMPTY Students in Musical Chairs: EMPTY What would you like to do now? 1. Test a new input file 2. Test another method on the same file 3. Quit Enter a number 2. setupseats This method creates the classroom seats. Imagine that someone is putting down seats on a rectangular or square room. - We will use a 2D array to simulate a room where each cell of the array can have a seat or not. - The instance variable seatingLocations is the 2D boolean array that shows which seats exist for students to seat at. - The instance variable students Sitting is the 2D array that contains the students when they are seating. To complete complete this method do: 1. Read the input file to create the seating arrangement for 2D boolean array seatingLocations 2. Initialize the 2D Student array students Sitting to be of the same size. The input file format is as follows: - The first line contains an integer representing the number of rows in the classroom, say r - The second line contains an integer representing the number of columns in the classroom, say c - Number of r lines, each containing c true or false values (true denotes a seat exists, false denotes that there is no seat at that position in the classroom) Use the Stdln library to read from a file: - stdin.setfile(filename) opens a file to be read - stdin. readint() reads the next integer value from the opened file (weather the value is in the current line or in the next line) - stdin.readboolean() read the next boolean value from the opened file (weather the value is in the current line or in the next line) 3. seatStudents This method simulates students taking their seats in the Kindergarten classroom. Assume that the students are currently in studentslnLine and that there are enough available seats to seat all students in the line. - This method will populate the 2D array studentsSitting. - Students will be seated starting at the first row, first seat (studentsSitting[0][0] if a seat is present at that location). Once the first row is filled, continues into the next row. - It uses the seatingLocations array to determine if a seat exists at a location. - A student can sit at seat studentsSitting[i][j] only if seatingLocations[i][j] is true (seat exists). - Then seat the first student in studentsInLine and moves on to the second, third and so on. NOTES - A student is only in one place (musical chairs, seating chairs, or in line) at a time. At the end of this method studentsinLine is empty. - This method depends on enterClassroom and setupSeats. Test those individually on the driver prior to testing this method. Students in Musical Chairs: M. Brow N. Dyer P. Ferg D. Harb M. Hawk C. Heat J. Keer G. Mata C. McLa D. Mont P. Reis W. Ryde N. Schn S. Sink F. Wolf - POINTS TO FRONT 6. insertByHeight Each student that is eliminated from the musical chairs game is put back in the line (studentsinLine linked list) by height order. - The eliminated student is given as as parameter - Iterate through studentsinLine searching for a student that is taller than the eliminated student. You will have 3 cases: - eliminated student is the shortest, insert at the front of the list. - eliminated student is the tallest, insert at the end of the list. - eliminated student is not the shortest or tallest, insert in the middle of the list. - When inserting into the list, a student will be insert AFTER all students of the same height. - Watch this video for more information. - This method is called from moveStudentFromChairs ToLine() to insert a student that was eliminated from the musical chairs game. In the driver, you can test this method independently using moveStudentFromChairsToLine. 7. eliminateLosingStudents This method eliminates all students from musicalChairs except the winner. 1. Obtain the number of students currently in the musicalChairs, call it size. 2. Repeatedly call moveRandom StudentFromChairs ToLine with the size until one player is left. 3. Don't forget to update size after each call as the number of students in the chairs decreases by 1. At the end of this method one student will remain in musicalChairs, this is the winner! The winner doesn't leave the musical chairs to enter the line. All other students will be standing on the line in ascending order by height. NOTE: this method depends on all previous methods. 8. seatMusicalChairsWinner This method will seat the winner of the musical chairs game! After the game of playMusicalChairs, you must seat the winner first! - If musical musicalChairs contains only one node (that is, the winner), delete the node. The list will be empty. - Insert the student object into the first empty spot in the classroom (seatingStudents). Implementation Notes - YOU MAY only update the methods with the WRITE YOUR CODE HERE line. - DO NOT add any instance variables to the Classroom class. - DO NOT add any public methods to the Classroom class. - YOU MAY add private methods to the Classroom class. - DO NOT use System exit() * This method simulates students standing in line and coming into the classroom (not leaving the 1 ine). It does this by reading students from input file and inserting these students studentsintine singly linked list. 1. Open the file using Stdin. setFile(filename); 2. For each line of the input file: 1. read a student from the file 2. create an object of type student with the student information 3. insert the Student object at the FRONT of the linked list * Input file has: * 1) one line containing an integer representing the number of students in the file, say x * 2) x lines containing one student per line. Each line has the following student * information separated by spaces: FirstName LastName Height * To read a string using Stdin use Stdin.readstring() * The input file has Students in REVERSE alphabetical order. So, at the end of this * method all students are in line in alphabetical order. * DO NOT implement a sorting method, PRACTICE add to front. * eparam filename the student information input file / public void enterclassroom (string filename ) \{ // WRITE YOUR CODE HERE * This method creates and initializes the seatingAvailability (2D array) of * available seats inside the classpoom. Imagine that unavailable seats are broken and cannot be used. 1. Open the file using StdIn. setFile(seatingChart); 2. You wil1 read the seating chart input file with the format: * An integer representing the number of rows in the classroom, say r * An integer representing the number of columns in the classroom, say c * Number of r lines, each containing c true or false values (true represents that a * seat is present in that column) 3. Initialize seatinglocation and studentssitting arrays with r rows and c columns 4. Update seatingLocation with the boolean values read from the input file ish > OneDrive > Desktop > CS111 > RUKindergarten > src > kindergarten > J Classroom.java > \& Classroom > Classroom(SNode, SNode, boolean[], Student]] 3
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