1. Homepage
  2. Programming
  3. Computer Science 21A (CS21A) - Data Structures and Algorithms - Programming Assignment 0: Up and Down

Computer Science 21A (CS21A) - Data Structures and Algorithms - Programming Assignment 0: Up and Down

Engage in a Conversation
CS21AComputer Science 21AData Structures and AlgorithmsBrandeisJavaElevator

  CourseNana.COM

Computer Science 21A (Fall, 2023) CourseNana.COM

Data Structures and Algorithms CourseNana.COM

  CourseNana.COM

Programming Assignment 0 – Up and Down CourseNana.COM

  CourseNana.COM

DUE: Thursday, September 7th, at 6:00 PM CourseNana.COM

Overview: CourseNana.COM

In this assignment, you will be simulating a building that contains a single elevator. However, this elevator is somewhat simplified: it only moves a person to a floor and then the person will remain on that floor forever. That is, the elevator cannot pick people up from any floor besides the lobby. CourseNana.COM

People will be entered into a building going to a specific floor. Two things need to happen. As a person arrives at the building, the elevator may or may not be in the lobby. To pick them up, the elevator (1) must be sent to the lobby to pick them up and then (2) bring them to their floor. CourseNana.COM

An elevator has a maximum number of people it can “carry” at a time. For instance, suppose an elevator can carry 3 people at a time and 5 people arrived in the lobby to be serviced by the elevator. The elevator would bring the first 3 people to their floors, then return to the lobby and bring the last 2 people to their floors. The order in which a group of people are brought to their floors is the order in which they requested use of the elevator (i.e., first-come-first-serve). Thus, the elevator will not be very efficient. CourseNana.COM

You will be coding an object-oriented solution, where you will need to implement the following classes. More details regarding their implementation will follow. CourseNana.COM

Building: A Building should hold an array of Floors and an instance of an Elevator. A Building will have a lobby and then floors numbered 1, 2, up to some maximum. CourseNana.COM

Floor: A Floor must contain an array of Person objects that are currently on the Floor. CourseNana.COM

Elevator: An Elevator will contain an array of Jobs where each Job holds a Person and the number of the floor which they desire to go to. All printing done in your program outside of Simulation.java should be done in the processJob() method of this class. This will be discussed in more detail on page 4. CourseNana.COM

Person: A Person has a first and last name and information regarding their location in a Building. CourseNana.COM

Job: A Job is used to represent a “request” to the elevator. This class holds a reference to a Person and a floor number. You can use a null Person to represent a Job that calls the Elevator to the lobby. CourseNana.COM

Simulation: This class should contain a main method where you simulate a Building. You should instantiate a Building, and several Person instances. Then you should simulate various arrivals of people arriving at different times and requesting to use the Building’s Elevator. It is recommended that you use this method to test your classes thoroughly. This is the only class where you should put print statements outside of Elevator. CourseNana.COM

  CourseNana.COM

Implementation Details: CourseNana.COM

In general, the client program should be able to create Person instances and a Building instance and then be able to add people to the Building’s Elevator and start it in various orders. For instance, one may choose to add a Person to the Building’s Elevator and start it. After this, two more Person instances could be added to the Building’s Elevator before starting it, and so on. The necessary details of each class that you will be creating to provide this functionality are described below. CourseNana.COM

  CourseNana.COM

Note: You must implement the following methods following these exact signatures. If a class does not have a specific constructor declaration, feel free to pass as many parameters into that class’ constructor as you see fit. You may use additional methods in your classes in order to have an organized and modular solution. CourseNana.COM

If you draw a simple diagram of how these classes will interact and what the flow of the program will be before you start coding, it will be easier to complete this assignment. CourseNana.COM

  CourseNana.COM

Building.java CourseNana.COM

  CourseNana.COM

           public Building(int numFloors)- This constructs a Building that has some number of floors. When you construct the Building, its Elevator should be at the lobby, and it should have floors 1, 2, …, numFloors above that. CourseNana.COM

  CourseNana.COM

           public boolean enterElevatorRequest(Person person, int floor) — This method will handle the request made by a Person to enter this Building and be taken to some floor. This will involve ensuring that the Person’s desired floor can be reached by this Building’s Elevator. If the Elevator cannot reach the Person’s desired floor, return false. If the elevator can reach the person’s desired floor, return true. This method should ensure that the Elevator will never process this Person’s request if it is not valid. CourseNana.COM

  CourseNana.COM

           public void startElevator() — This will call a method in this Building’s Elevator instance that should process all of its current Jobs. CourseNana.COM

  CourseNana.COM

           public void enterFloor(Person person, int floor) — This method should save a reference of a Person in the Floor with the provided floor number. CourseNana.COM

  CourseNana.COM

Person.java CourseNana.COM

  CourseNana.COM

           public Person(String firstName, String lastName) – This will construct a Person with a given first and last name. CourseNana.COM

  CourseNana.COM

           public boolean enterBuilding(Building building, int floor) — This method will enter this Person into a Building’s Elevator with a provided destination floor number. This should return true if the Person can be brought by the elevator to ‘floor’ and false if not. You may assume a Person will only ever try to enter one Building. CourseNana.COM

  CourseNana.COM

      public String getLocation() — This should return this Person’s location as a String. To do this, you should maintain a field that tracks this Person’s location in some way. When this method is called it should return the following exact Strings: CourseNana.COM

o   “Waiting to be serviced” from the time this Person is validated by a Building (to be processed) to the time they arrive on their desired Floor. CourseNana.COM

o   “In Lobby” if this Person is in a Building’s lobby and will never be serviced by the Building’s Elevator. CourseNana.COM

o   “In Floor x” if this Person is on Floor number x. CourseNana.COM

Note that getLocation() will never be called while the elevator is moving, i.e. if a person is in the lobby and then moves to Floor 3, this method won’t get called while they are on Floor 1 and Floor 2, so you will not need to track their movement on the intermediate floors for this method. CourseNana.COM

Job.java CourseNana.COM

  CourseNana.COM

This class may be implemented how you choose. Its primary purpose is to store requests for the Elevator to service. Each request comprises of a Person and the number of the floor they wish to be taken to. CourseNana.COM

  CourseNana.COM

Elevator.java CourseNana.COM

  CourseNana.COM

When implementing methods that create and process Jobs, remember that Jobs are handled first-come-first-serve. This class includes a single static field maxOccupants which specifies the maximum number of people an Elevator can bring to their Floors at a time. You must be using this static field in your implementation. You cannot remove it, but feel free to test your code for values other than 3.

CourseNana.COM

           public Elevator(// whatever params you want) – This should construct an Elevator on the lobby with no current Jobs.

CourseNana.COM

           public void createJob(Person person, int floor) — This method should add a new job to be completed by this Elevator given a Person and their desired floor number. CourseNana.COM

  CourseNana.COM

           public void processAllJobs() — This method should remove jobs one by one and process them. CourseNana.COM

  CourseNana.COM

           public void processJob(Job job) — This method should process a Job. This will involve moving this Elevator from its current floor to the Floor indicated by the provided Job. Once the desired Floor is reached, you should use the exit() method to move the Job’s Person to their destination Floor in their Building. CourseNana.COM

You must print the Elevator’s location before you move it and after each time you move the Elevator by a floor (either up or down). CourseNana.COM

o    When the Elevator is in the lobby print “Elevator at Lobby”. CourseNana.COM

o    When the Elevator is on floor x, print “Elevator at floor x” CourseNana.COM

  CourseNana.COM

     For instance, a job processing could involve moving this Elevator from the lobby                               to floor 2. The printed output for this would look like: CourseNana.COM

  CourseNana.COM

            Elevator at Lobby CourseNana.COM

     Elevator at floor 1 CourseNana.COM

     Elevator at floor 2 CourseNana.COM

  CourseNana.COM

     A job processing may also involve moving an Elevator down to a floor. Say the                                  Elevator starts on floor 3 and needs to go to floor 1. The printed output for this                               would look like: CourseNana.COM

  CourseNana.COM

            Elevator at floor 3 CourseNana.COM

     Elevator at floor 2 CourseNana.COM

     Elevator at floor 1 CourseNana.COM

  CourseNana.COM

           public void exit(Person person, int floor) — This method should remove a Person from this Elevator onto their Floor in the Building the Person is in. CourseNana.COM

  CourseNana.COM

Floor.java CourseNana.COM

CourseNana.COM

           public Floor(// whatever params you want) – This should construct a Floor.  It is up to you what is tracked in the object and how it is constructed. CourseNana.COM

           public void enterFloor(Person person) — This method should save a reference of the Person within this Floor object CourseNana.COM

Simulation.java CourseNana.COM

This class should be used to run your Simulation. In this class, you should only be constructing Person and Building objects. You should not be interacting with your Elevator class at all. The methods you should be using are: enterBuilding() to enter a Person into a Building and startElevator() to have the Elevator in your Building begin processing its Jobs. CourseNana.COM

Lastly, you must write a toString() method with your own implementation for each class. CourseNana.COM

  CourseNana.COM

If you think that you need extra classes, feel free to implement them. However, make sure to explain why you added them and what advantage they give your program in your README file. We are not looking for a uniquely right solution, so use your own judgement as a programmer and describe your logic in a README.txt file in addition to thoroughly commenting your code. CourseNana.COM

JUnit Tests CourseNana.COM

In the “tests” package of the Eclipse project distributed on LATTE, there are 5 JUnit test files corresponding to the 5 classes you must write. You must write JUnit tests for at least 2 of these classes. It is recommended that you use your classes’ toString() methods to write the tests. CourseNana.COM

If you write JUnit tests for additional classes, you will receive extra credit. CourseNana.COM

Debugging CourseNana.COM

The Eclipse debugger would be quite useful for this assignment. If you are not comfortable with the debugger, you should use print statements along with classes’  toString() methods to isolate the source of an error. CourseNana.COM

However, when you submit your assignment, make sure that you remove all print statements besides the required ones in processJob(). CourseNana.COM

Important Notes CourseNana.COM

You should NOT import any libraries, such as java.util.Arrays, or Java collections in your code. The only Java-provided data structure that you will be using is an array.  Hint: Since you will be using static arrays, you have to specify their size on construction.  However, a few objects in this assignment will not have a known size when you instantiate them, so you will need to deal with adding potentially arbitrarily large numbers of people into your building (within reason, we aren’t going to use up all your memory or anything like that). CourseNana.COM

Lastly, double-check the following: CourseNana.COM

1) Outside of Simulation.java, make sure you are printing only in processJobs()and that you are printing the exact Strings described on page 4 before moving the Elevator and after every time it is moved by 1 Floor. CourseNana.COM

2) Make sure that you are returning the exact Strings in getLocation() described on page 3. CourseNana.COM

  CourseNana.COM

Submission Details CourseNana.COM

  CourseNana.COM

      For every non-test method you write, you must provide a proper JavaDoc comment using @param, @return, etc. CourseNana.COM

      At the top of every file that you submit please leave a comment with the following format. Make sure to include each of these 6 items. CourseNana.COM

  CourseNana.COM

     /** CourseNana.COM

      * <A description of the class> CourseNana.COM

      * Known Bugs: <Explanation of known bugs or “None”> CourseNana.COM

      * CourseNana.COM

      * @author Firstname Lastname  CourseNana.COM

      * <your Brandeis email> CourseNana.COM

      * <Month Date, Year>  CourseNana.COM

      * COSI 21A PA0 CourseNana.COM

      */ CourseNana.COM

  CourseNana.COM

>Start of your class here< CourseNana.COM

      Use the provided skeleton Eclipse project. CourseNana.COM

      Submit your assignment via Latte as a .zip file by the due date. It should contain: CourseNana.COM

1) Your solution in an Eclipse project. CourseNana.COM

2) Your README.txt (more on this on page 5 and 6) CourseNana.COM

      Name your .zip file LastnameFirstname-PA0.zip CourseNana.COM

      Late submissions will not receive credit. CourseNana.COM

  CourseNana.COM

Sample Output CourseNana.COM

  CourseNana.COM

See next page. CourseNana.COM


CourseNana.COM

  CourseNana.COM

Consider a building with 3 floors and let there be 2 people, A and B. Person A enters the building first and requests floor 2, then Person B enters and requests floor 3. Finally, the elevator is started. Then the expected output will be: CourseNana.COM

  CourseNana.COM

Elevator at Lobby CourseNana.COM

Elevator at floor 1 CourseNana.COM

Elevator at floor 2 CourseNana.COM

Elevator at floor 2 CourseNana.COM

Elevator at floor 3 CourseNana.COM

  CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
CS21A代写,Computer Science 21A代写,Data Structures and Algorithms代写,Brandeis代写,Java代写,Elevator代写,CS21A代编,Computer Science 21A代编,Data Structures and Algorithms代编,Brandeis代编,Java代编,Elevator代编,CS21A代考,Computer Science 21A代考,Data Structures and Algorithms代考,Brandeis代考,Java代考,Elevator代考,CS21Ahelp,Computer Science 21Ahelp,Data Structures and Algorithmshelp,Brandeishelp,Javahelp,Elevatorhelp,CS21A作业代写,Computer Science 21A作业代写,Data Structures and Algorithms作业代写,Brandeis作业代写,Java作业代写,Elevator作业代写,CS21A编程代写,Computer Science 21A编程代写,Data Structures and Algorithms编程代写,Brandeis编程代写,Java编程代写,Elevator编程代写,CS21Aprogramming help,Computer Science 21Aprogramming help,Data Structures and Algorithmsprogramming help,Brandeisprogramming help,Javaprogramming help,Elevatorprogramming help,CS21Aassignment help,Computer Science 21Aassignment help,Data Structures and Algorithmsassignment help,Brandeisassignment help,Javaassignment help,Elevatorassignment help,CS21Asolution,Computer Science 21Asolution,Data Structures and Algorithmssolution,Brandeissolution,Javasolution,Elevatorsolution,