Code the following
Grade class in a new class category
The built-in libraries of Smalltalk make very effective use of
abstract classes. The
Magnitude class is an abstract
class which allows comparisons
Character are all subclasses of
Write a new magnitude class
Grade, a subclass of
Magnitude, which is a letter grade ranging from F-
aGrade := Grade letter: $A modifier: #plus--makes a new A+ grade object. Modifiers can be
#none. (Recall that
$Ais the character constant A).
aGrade := Grade new: 'A+'--a friendlier way to make a new A+ grade object.
aGrade letter--the letter portion of the grade,
aGrade modifier--the modifier portion,
aGrade increment-- bump the grade up by one full letter grade
aGrade decrement-- bump the grade down by one full letter grade
aGrade points--how many points the grade is worth, e.g. 4 for A, 3 for B, etc. The + adds .3 and a - subtracts .3. Also, an A+ is is an exception, its only worth 4.0, not 4.3.
aGrade op anotherGradewhere
opis any comparison such as
= < > ~=: compare grades in the standard way: B < B+, etc.
Magnitudeprotocol works (i.e. you have implemented everything that was the subclassResponsibility to implement), with the exception of
hash(that really should be done, but we'll skip it for now).
printOn: aStreammethod so the grades get printed nicely in the workspace. (This is the method you have to write to get a nice print name for objects; the
printStringmethod discussed in class in fact calls
aStreamargument is a stream which is in fact the workspace buffer. All you need to know about streams for now is that
aStream nextPutAll: 'A+'
Assignment1.st, and then submit this file from hops via the precise (no exceptions in names, please) hops command
~scott/bin/submit Assignment1 Assignment1.st(The general format for this command is the name of the assignment followed by the file(s) submitted)
You will need to ftp your files to hops first if you are working on some other machine.
Don't submit a
.im file, they are too
big! Use the file in/out tool instead.
You can check what files you submitted via
~scott/bin/queryAll of your solutions should work in VisualWorks Smalltalk 3.0.