Code the following Grade
class in a new class category
named precisely Assignment1
.
The built-in libraries of Smalltalk make very effective use of
abstract classes. The Magnitude
class is an abstract
class which allows comparisons <
, =
,
etc. Date
, Time
,
Character
are all subclasses of
Magnitude
.
Write a new magnitude class Grade
, a subclass of
Magnitude
, which is a letter grade ranging from F-
to A+.
aGrade := Grade letter: $A modifier: #plus
--makes a new
A+ grade object. Modifiers can be #plus
,
#minus
, or #none
. (Recall
that $A
is 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, $A
here.
aGrade modifier
--the modifier portion,
#plus
here.
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 anotherGrade
where
op
is any comparison such as = < >
~=
: compare grades in
the standard way: B < B+, etc.
Magnitude
protocol
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: aStream
method 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
printString
method discussed in
class in fact calls printOn:
).
The aStream
argument is a stream which is in fact the
workspace buffer. All you need to know about streams
for now is thataStream 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.