X-Git-Url: https://git.llucax.com/z.facultad/75.62/c2tp1.git/blobdiff_plain/9d7e2a457ef6f0b2ee369ea066af2b89eca79ad2..HEAD:/src/Fraccion.java?ds=sidebyside diff --git a/src/Fraccion.java b/src/Fraccion.java index 7cf9d86..33111f0 100644 --- a/src/Fraccion.java +++ b/src/Fraccion.java @@ -1,41 +1,6 @@ +import java.util.*; -class CeroDenExc extends Exception { - - private int num; - - public int getNum() { - return num; - } - - public void setNum(int n) { - num = n; - } - - public CeroDenExc(int num) { - setNum(num); - } - - public String toString() { - return "Division por 0 (numerador = " + getNum() + ")"; - } - -} - -interface OperFrac { - - public Fraccion mas(Fraccion f); - - public Fraccion menos(Fraccion f); - -} - -interface ComparaFrac { - - public int compareTo(Fraccion f); - -} - -class Fraccion implements OperFrac, ComparaFrac { +public class Fraccion extends Observable implements OperFrac, ComparaFrac { private int num; private int den; @@ -50,10 +15,14 @@ class Fraccion implements OperFrac, ComparaFrac { public void setNum(int n) { num = n; + setChanged (); + notifyObservers (); } public void setDen(int d) { den = d; + setChanged (); + notifyObservers (); } public Fraccion() { @@ -122,23 +91,8 @@ class Fraccion implements OperFrac, ComparaFrac { int d = mcd(getNum(), getDen()); setNum(getNum() / d); setDen(getDen() / d); - } - - // Test - public static void main(String args[]) throws CeroDenExc { - try { - Fraccion f = new Fraccion(10, 0); - } catch (CeroDenExc e) { - System.out.println("Ahhh! Esta rota la fraccion!" - + " tiene numerador " + e.getNum() + " y divisor 0"); - } - Fraccion f1 = new Fraccion(2, 10); - System.out.println("f1 = " + f1); - System.out.println("f1 + f1 = " + f1.mas(f1)); - Fraccion f3 = f1.menos(new Fraccion(100, 4)); - System.out.println("f3 = " + f3); - System.out.println("f3 comparado a f1 = " + f3.compareTo(f1)); - //System.out.println("Java esta roto en el manejo de excepciones!!!"); + setChanged (); + notifyObservers (); } }