38 lines
652 B
D
38 lines
652 B
D
module duck;
|
|
|
|
import std.conv : to;
|
|
import std.stdio : writeln;
|
|
|
|
class Duck
|
|
{
|
|
private string name;
|
|
private int weight;
|
|
|
|
this(string name, int weight)
|
|
{
|
|
this.name = name;
|
|
this.weight = weight;
|
|
}
|
|
|
|
override string toString() const @safe pure nothrow
|
|
{
|
|
return name ~ " weighs " ~ weight.to!string;
|
|
}
|
|
|
|
int opCmp(const Duck otherDuck) const @safe pure nothrow
|
|
{
|
|
if (weight < otherDuck.weight)
|
|
{
|
|
return -1;
|
|
}
|
|
else if (weight == otherDuck.weight)
|
|
{
|
|
return 0;
|
|
}
|
|
else
|
|
{
|
|
return 1;
|
|
}
|
|
}
|
|
}
|