Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Requirements for milestone1:
Create a series of classes which will allow us to create a Form that is a mathematical equation.
- MathEquation will be the class that understands from: and will return an object that responds to display and displayOn:.If it gets a string, it just returns a graphical representation of that string. However, if it gets a different mathematical object, it will return that object AS A DISPLAYABLE OBJECT.
- MathFraction has a class method from:over: that constructs a fractional object. MathEquation must format that properly.
- MathOperation has a class method operator:with:and: that allows math objects to be combined. Operators are just strings. The arguments to with:and: should be strings or math objects, e.g., MathOperation operator: '+' with: (MathSuperscript from: '(x+2)' with: '2') and: '2'
- GreekSymbol has a class method named:sized: that takes a symbol and returns a math object of the appropriate symbol at the appropriate size (10, 12, 14, or 18, only). See greek.pdf for tables of Greek character names (which you should use for symbols, e.g., #Pi and #alpha) and their corresponding images.
- MathSuperscript and MathSubscript understand from:with: which creates a mathematical object of the from: argument either superscripted of subscripted with the with: argument.
Additional files needed for milestone1:
Ypatia.st to display Greek Symbol. (Note: you'll need to filein ypatia.st and execute Ypatia installAsTextStyle in workspace to install it.)
UML diagram for milestone1
CRC cards for milestone1
Analysis of design and description of classes:
In this project, I created 6 classes: GreekSymbol, MathEquation, MathFraction,MathOperation, MathSubscript and MathSuperscript.
The class methods of the above classes (except MathEquation) will return an instance of the class itself which is a displayable mathmetical object. And from: is a message understood by class MathEquation. The argument of message from: can be a string or a math object, if the argument is a string then just return a displayable Form. If the argument is a math object, then the math object's instance method makeForm is invoked.
Each individual class (except MathEquation) has an instance method makeForm, when it's invoked it will check whether the object is a string or math object, if it's a string, just return it as a displayable form, if it's a math object, just invoke the math object's makeForm.
What we learned and what we need to do for the later milestones:
At the beginning of the design stage, I was pretty confused about "what does each thing return? " and "who calls what?" types of questions. A typical thought of procedural language.
For example: What should (MathFraction from: 'sin(x)' over: 'x') return? It could be a form. But the size will be fixed,so if this form is a superscript in the next message and then we can't make it small. So I designed to let it return an instance of the class MathFraction, holding the numerator and denominator as instance variables.
Regarding to at what point do we convert it to a Form (or something else) and who should do it, I designed to let the object itself to do it, in this example let the fraction to represent a fraction as a Form. Then we can send messages to mathFraction object and let it display itself at whatever size.
Now I got the Form for any given piece of the equation, and the Form understand the message boundingBox which will tell the size of itself. At this point,given the size of any Form, and having the desired equation (e.g., what's a superscript, what's a fraction),it's easy to figure out where things need to sit in order to create the right equation.
The only problem for the milestone1 was that for mathOperation, I didn't have time to make the alignment well, the operator is not sit on the right position. And we can easily fix this problem in the later milestones.
Some testing scripts and results:
note: type the following code in workspace, hit alt-d, and the form will be displayed on the upper left corner of the squeak window.
- (MathEquation from:'cs2340') display
- (MathEquation from: (MathFraction from: 'sin(x)' over: 'x')) display
- (MathEquation from: (MathFraction from: (MathSuperscript from: '5' with: '3') over: 'x')) display
- (MathEquation from: (MathFraction from: (MathSubscript from: 'H' with: '3') over:(MathSuperscript from: 'X' with: '2') )) display
- (MathEquation from:(MathOperation operator:'+' with: ((MathFraction from:(MathSuperscript from:'X' with: '3') over:(MathSubscript from: 'X' with: '2') ) and:'3') display
- (MathEquation from:(MathOperation operator:'=' with:(MathFraction from:(GreekSymbol named: alpha sized: 24) over:'8') and:(MathFraction from:(GreekSymbol named: lambda sized: 24) over:'cs2340'))) display
Link to this Page