Over the last several lessons, you've learned all about how to use modularity to break down a problem. You even picked up some tips on how to make your modules perform better. In this assignment, you'll be asked to take apart a more complicated problem and pseudocode up the design for its solution.
To do this, you could simply jam all the code into one long script but it would be an instance of one giant "god" module so you know that's a bad idea. Practice thinking of each subtask as a separate module.
The goal for this exercise is NOT to rigorously apply all the SOLID principles (and you can't do this anyway with the simple pseudocode you've learned). We instead want you to think in terms of modules and to recognize when the problem needs to be separated into them.
You live in a 25 story building with one elevator. The central microcontroller got eaten by rats and the building manager has asked you to code up the elevator's operating procedure until he can get a new one. You figure you'll have to learn to actually code soon but you first want to think things through and pseudocode your design.
The basic elevator machinery is completely dumb (it doesn't do anything it's not told to do) but is capable of interpreting and executing the commands:
...and it accepts user input in the form of:
...and it has sensors for:
...and it has a few quirky requirements:
Your job is to design a properly working elevator. It should stop on each floor it is physically able to during a given trip to pick up whoever is going the same direction. Additionally, make sure that no one is:
This will be good practice thinking about all the edge cases and scenarios that a user can do.
The point isn't to follow any strict guidelines of syntax but rather to focus on getting the logic of the problem figured out and then organizing it into modules that accomplish the sub-tasks that are required.
This exercise is large enough that you will need to break your code up into modules. Remember the SOLID lessons -- modules should only have one major purpose. For this exercise, you can use other modules by simply calling their name in plain english and writing them out as separate programs down below your main program. They could be groups of procedural instructions like "slow down the elevator if necessary", which runs the "ReachedADestinationFloor?" program.
PROGRAM Elevator: # other code slow down the elevator if necessary # other code END # other code PROGRAM SlowDownIfNecessary IF we are traveling up at full speed IF we are only 1 floor away from the lowest destination floor slow down END ELSE IF we are traveling down at full speed IF we are only 1 floor away from the highest destination floor slow down END END END
You have everything you need to design your elevator. Up, up and away!