Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For an elevator simulation, there is a need for a \"WaitLine\" class to store \"

ID: 3624865 • Letter: F

Question

For an elevator simulation, there is a need for a "WaitLine" class to store "Person" objects waiting in a
line for the appropriate elevator.find links for those below. The WaitLine class is basically a queue (add to end, remove from start), implemented with an ArrayList.
It should have Instance variables
-Arraylist of type Person to store the line integer for the maximum length the line actually gets with Person objects doing a simultation run (this is for comparison purposes between the different elevator
simulations).
Default Constructor "WaitLine()" - instantiates the ArrayList to default size, takes default value
for "maximum length the line actually gets".
Accessor Method - "int getLength()" - returns "current number of Person objects in the line".
Mutator Methods -
"boolean addPersonEnd(Person p)" - clones the Person object passed as an argument to
the next available position in the line and returns true (if enough room in the line), else
returns false. Also, possibly updates the "maximum length the line actually gets".
"Person removePersonStart()" - If there is no Person objects in the list, return null.
Otherwise, return the first Person object in the list and move all the other Person objects up
one space in the list.
toString() Method - output each Person object in the list, one to a line, and output the maximum length the line actually gets

AS PROMISED FIND BELOW THE PROVIDED WaitLine shell class and Person shell class at the following links

http://www.cs.iit.edu/~cs201/labs/Lab11/Person.java
http://www.cs.iit.edu/~cs201/labs/Lab11/WaitLineClient.java

(you can just open tabs for each and copy the link into the browser to view the provided shell classes)

PLEASE FIND BELOW MY WaitLine class. It only outputs only what I passed in the toString method. PLS HELP!


import java.util.ArrayList;
public class WaitLine
{
ArrayList line = new ArrayList();
public static final int MAX_PEOPLE = 100;
private int length;

public WaitLine()
{
new ArrayList(MAX_PEOPLE);
}

public int getLength()
{
return length;
}

public void setLength(int newLength)
{
if (newLength > 0 && newLength < 100)
length = newLength;
else length = MAX_PEOPLE;
}

boolean addPersonEnd(Person p)
{
//WaitLine temp = WaitLine.clone();<==need help trying to clone this;
if ((line.size() < 0) && (isFull()))
return false;
else return true;
}

boolean isFull()
{
int numPeople = 0;
return(numPeople == line.size());
}

public WaitLine clone()
{
return new WaitLine();
}


Person removePersonStart()
{
Person first;
if (line.size() == 0)
return null;
else
first = line.get(0);
line.remove(0);
return first;
}

public String toString()
{
String output = " ";
for (int i=0; i < line.size(); i++)
{
output += "Person"+ i+ "is " +" and the maximum the length of the line is "+ MAX_PEOPLE;
}
return output;
}
}
Pls correct my code accordingly because I am not too conversant with ArrayList yet. Thanks in advance

Explanation / Answer

Added comments where I changed/corrected things //in this form ********* Hopefully it works, if not let me know. Here's the code: import java.util.ArrayList; public class WaitLine { ArrayList line = new ArrayList(); public static final int MAX_PEOPLE = 100; private int length; public WaitLine() { line = new ArrayList(MAX_PEOPLE); } public int getLength() { return length; } public void setLength(int newLength) { if (newLength > 0 && newLength < 100) length = newLength; else length = MAX_PEOPLE; } boolean addPersonEnd(Person p) { // WaitLine temp = WaitLine.clone();
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote