Module Design - Lesson Object

Designed by: Kunal Mittal
Version: 1.2 28th. April 1998.

Overview: This object maintains all the details about the lesson currently in memory. It handles the opening, saving, restarting and check correctness of a lesson.
Format of lesson URL: The lesson URL will store four pieces of data. The very first line of this file will contain an url to the lessonInstructions. The second line will contain two characters without a space. The first character will be one of "S", "D", or "T" for the nodeType and the second character will be "I" or "S" for int or string nodes. These will be in upper case. The next lines will contain the code to construct the initial screen. The last few lines will contain the code regarding the endstate of the lesson. The lines of code that are to be used to construct the initial screen and the lines of code that are used to construct the end-state, will be separated by a blank line.

Private Data:
string lessonInstructions: This is the text description of the lesson as entered by the creator of the lesson. This is what is shown when the user clicks "Show Instructions".
string startCode: This stores the code to construct the start state of the lesson. Storing this is useful when we re-start a lesson.
MasterNodeObject nodeEndState: Stores the final state of the lesson. This will be used to check whether the user has completed the lesson or not.

public void ShowInstructions(void)
Overview: Displays the instructions for the lesson in a pop-up window.
Parameters: None
Pre-conditions: The lessonInstructions string has be initialized to some text.
Post-conditions: A pop-up window is opened or an existing window is brought to the front, with the lesson instructions in it.
Algorithm: Manipulation of internal data.
Interaction with other Objects: None.
Error conditions: This method should not be called before a LoadLesson() method call.
Return Value: None.
public boolean CheckDone(void)
Overview: Compares two MasterNode objects. It returns whether the lesson has been successfully completed or not. Since Java does not allow operator overloading, it needs to be faked appropriately.
Parameters: None.
Pre-conditions: None.
Post-conditions: None.
Algorithm: Will be discussed in a future release.
Interaction with other Objects: MasterNode and Node objects.
Error conditions: None.
Return Value: Returns "true" if lesson evaluates to be correct and "false" otherwise.
public void LoadLesson(URL lessonURL)
Overview: Loads a lesson from the url mentioned. It also creates the end-state variables and sets the lesson instructions.
Parameters: Valid url where the lesson text and lesson instructions are stored. If the URL is NULL, then reload the start state from the startCode variable already stored.
Pre-conditions: None.
Post-conditions: A lesson is loaded into the memory. It sets the lesson text, calls ShowInstructions() and sets the end-state variables. It also constructs the start state and displays it on the screen.
Algorithm: Load the url mentioned. If the URL is not NULL , then parse the url as follows. The first line will contain an url to the lesson instructions. Read that file and store it in the lessonInstructions variable. Then read the two characters on the second line and assign the MasterNode object appropriately. Then read each line until a blank line and store them in the startCode variable. The lines after the blank line contain the code to construct the endState variables. Send these lines to the command line or to the loop object as required. If the URL passed in as a parameter to this function is NULL then start the algorithm from here on. Call LoadStartState. Clear the log file and all the data entry fields (ie. the command entry field and the loop dialog).
Interaction with other Objects: Initializes MasterNode to store the end state. It will call the Command, Parser and Loop objects.
Error conditions: If the URL is invalid, throw an exception. Also, if we call this method with no url, it attempts to load the start state from the currently existing variables. Thus, we must make sure that the first time we call this method, we pass in a VALID url.
Return Value: None.
public void SaveLesson(string emailAddress)
Overview: Email the current state of the program to the user.
Parameters: The email address of the user.
Pre-conditions: None.
Post-conditions: An email is sent to the user, with the lesson text and instructions. They can save it to a file if they choose.
Algorithm: Parse the email address string and return any errors (look at Error Conditions). Get the command log (variable called "executed") from the Command Line Object. Open a data entry box to read in the lessonInstructions from the user. Then ask the user to go on and create the endState. Strip the comments and blank lines. Get the nodeType for "S", "D" or "T" and also int or string from the Master Node object. Then email all this to the user in the format described for the file that is used for LoadLesson(). This file will have the extension ".les".
Interaction with other Objects: Command Line, Error Object, MasterNode object.

Error conditions: If the email address entered is invalid, we just ignore it. An email address is invalid if it doesn't have

  • One and only one "@" symbol.
  • At least one "." symbol.
Return Value: None.
**private void LessonInstructions(string instructionsLocations)
Overview: Load the lesson text into the private variables.
Parameters: A string with the instruction text.
Pre-conditions: None.
Post-conditions: Checks to see whether the instruction file is valid.
Algorithm: Manipulation of internal data.
Interaction with other Objects: Error Object.
Error conditions: If parameter string is NULL return an error. If the url could not be found throw an exception.
Return Value: None.
private void LoadStartState( void )
Overview: Load the start state of the program.
Parameters: None.
Pre-conditions: None.
Post-conditions: A start state is loaded into memory.
Algorithm: Send the startCode variable to the parser line by line. If there is a loop, detect it here and send the entire loop to the loop object. The only parsing that needs to be done here is the detection of a loop. This is simple, as when reading in a line from the variable, check if it matches either whether the first word is a "while" or a "for". At this stage we need to do brace matching to find the end of the loop. This can be done with a simplified version of the parser. These statements form a loop. Store them in a temporary variable and send them to the loop object. The loop object should be able to accept a loop passed in as a string.
Interaction with other Objects: Command and Loop Object.
Error conditions: None.
Return Value: None.


Search engine sitemap created by