#
# A class for rational numbers
#

package Stats;

sub new {
	my ($class) = shift;
	bless {
		"sum" => 0,
		"count" => 0,
		"max" => 0,
		"data" => []
	}, $class;
}

sub max {
	my($self) = shift;
	return $self->{"max"};
}
sub addItem {
	my($self) = shift;
	my($newItem) = shift;

	$self->{"data"}[$self->{"count"}] = $newItem;
	$self->{"count"}++;
	$self->{"sum"} += $newItem;
	if ($self->{"max"} < $newItem) {$self->{"max"} = $newItem;}

}

sub average {
	my($self) = shift;
	if ($self->{"count"} == 0) { return 0; }
	return $self->{"sum"} / $self->{"count"}; #/
}

sub toString {
	my($self) = shift;
	my($count) = $self->{"count"};
	my($max) = $self->{"max"};
	my($sum) = $self->{"sum"};
	my($data, $i);
	$data = "";
	for($i =  0; $i < $count; $i++)
	{
		$data = "$data(" . $self->{"data"}[$i]. ")";
	}
	return "Count: $count Max: $max Sum: $sum Items: $data";
}


1;
