#
# A class for rational numbers
#

package Fraction;

sub new {
	my ($class) = shift;
	bless {
		"top" => 0,
		"bot" => 0
	}, $class;
}

sub set {
	my($self) = shift;
	my($newtop) = shift;
	my($newbottom) = shift;

	$self->{"top"} = $newtop;
	$self->{"bot"} = $newbottom;
}

sub toString {
	my($self) = shift;
	my($top) = $self->{"top"};
	my($bot) = $self->{"bot"};

	return "$top / $bot";
}

sub add {
	my($self) = shift;
	my($f2) = shift;
	my($top) = $self->{"top"};
	my($otop) = $f2->{"top"};
	my($bot) = $self->{"bot"};
	my($obot) = $f2->{"bot"};
	$self->set($top*$obot + $otop * $bot, $bot * $obot);
}

1;
