home4/description.html

70 lines
2.9 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>i231.fraction.v2</title>
</head>
<body>
Write an implementation (class <code>Lfraction</code>) for an abstract data
type "Fraction", where the fraction consists of two long integers:
numerator and denominator. Always convert
fractions to a form, where denominator is strictly positive and
the fraction is reduced. By default all operations (described on webpage
http://www.itcollege.ee/~jpoial/algoritmid/Lfraction/index.html ) must be exact
and use integer arithmetics only (e.g. do not use floating point arithmetics
to compare two fractions).
<br><br>
Remark 1. In addition to public methods listed you may need
a method to find the greatest common divisor of two integers to reduce
the fractions.
<br>
Remark 2. Operations must not modify operands, a new fraction must be
created for the result.
<br>
Remark 3. Methods <code>toString</code> and <code>valueOf</code> must
be dual: method <code>valueOf</code> must be able to interpret all
strings generated by the method <code>toString</code> .
<br>
Remark 4. If an error occurs (division by zero, illegal string, etc.)
the program must throw an exception of class <code>RuntimeException</code>
(or any appropriate subclass of <code>RuntimeException</code>).
<br>
Remark 5. Sign of a fraction is in numerator and integer numbers
expressed as fractions must have denominator 1, e.g.
3 is 3/1 , -5 is (-5)/1 and 0 is 0/1 .
<br><br>
Realiseerida abstraktne andmetüüp "murd pikkade täisarvude paarina".
<br>
Murdu esindab objekt klassist <code>Lfraction</code>, mis sisaldab murru
lugejat (ingl.k. numerator) ja murru nimetajat (ingl.k. denominator)
pikkade täisarvudena (teha nii, et nimetaja oleks alati rangelt positiivne
ning murd taandatud).
<br>
Realiseerida kõik operatsioonid, mis on kirjeldatud programmitoorikus (ja
veebilehel http://www.itcollege.ee/~jpoial/algoritmid/Lfraction/index.html ).
Murdude võrdlus peab olema täpne, s.t. toetuma arvutustele täisarvudega,
mitte reaalarvuliste lähiväärtustega.
<br><br>
Märkus 1. Lisaks loetletud avalikele meetoditele on teil tõenäoliselt
tarvis murru taandamise meetodit ja võib-olla ka kahe täisarvu
suurima ühisteguri leidmise meetodit.
<br>
Märkus 2. Reeglina ei tohi meetodid muuta objekti, millele neid rakendatakse
(näit. liitmisel ei tohi muuta liidetavaid, tuleb summa jaoks luua uus murd).
<br>
Märkus 3. Sõne teisendamisel murruks peab <code>valueOf</code>-meetod
olema kooskõlas <code>toString</code>-meetodiga (peab oskama tõlgendada
niisugust sõnet, mida <code>toString</code> tagastab).
<br>
Märkus 4. Veasituatsioonid (sõne, mida ei saa teisendada; nulliga jagamine
jt.) peavad tekitama erindi klassist <code>RuntimeException</code> või mõnest
selle klassi sobivast alamklassist.
<br>
Märkus 5. Murru märk käib lugeja juurde ning täisarvude nimetaja on 1 (ka
arvu 0 puhul).
<br><br>
</body>
</html>