From: Leandro Lucarella Date: Tue, 2 May 2006 19:14:33 +0000 (+0000) Subject: Refactoriza clases de Angulo y Fraccion. X-Git-Tag: darcs_import~7 X-Git-Url: https://git.llucax.com/z.facultad/75.62/c2tp1.git/commitdiff_plain/f9ae0eb22d1b5e8b12030d43c77c634c81743e73?ds=sidebyside;hp=730f65e26702338c2fea2a133c2df73de422c27d Refactoriza clases de Angulo y Fraccion. Separa las clases/interfaces auxiliares de Angulo y Fraccion, cada una en su propio archivo, para que sigan la Java-way. TambiƩn se saca para afuera los tests que tienen sus propias clases. --- diff --git a/src/Angulo.java b/src/Angulo.java index 2abe424..34e24cc 100644 --- a/src/Angulo.java +++ b/src/Angulo.java @@ -1,19 +1,5 @@ -interface OperAng { - - public Angulo mas(Angulo f); - - public Angulo menos(Angulo f); - -} - -interface ComparaAng { - - public int compareTo(Angulo f); - -} - -class Angulo implements OperAng, ComparaAng { +public class Angulo implements OperAng, ComparaAng { private int signo; private int grados; diff --git a/src/AnguloTest.java b/src/AnguloTest.java new file mode 100644 index 0000000..f71c68f --- /dev/null +++ b/src/AnguloTest.java @@ -0,0 +1,23 @@ + +public class AnguloTest { + + // Test + public static void main(String args[]) { + Angulo a1 = new Angulo(2, 10, 20); + System.out.println("a1 = " + a1 + " (" + a1.toRadianes() + ")"); + System.out.println("a1 + a1 = " + a1.mas(a1) + " (" + a1.mas(a1).toRadianes() + ")"); + Angulo a2 = new Angulo(-500, 4, 40); + System.out.println("a2 = " + a2 + " (" + a2.toRadianes() + ")"); + Angulo a3 = a1.menos(a2); + System.out.println("a3 = a1 - a2 = " + a3 + " (" + a3.toRadianes() + ")"); + Angulo a4 = a2.mas(a1); + System.out.println("a4 = a2 + a1 = " + a4 + " (" + a4.toRadianes() + ")"); + System.out.println("a2 comparado a a1 = " + a2.compareTo(a1)); + System.out.println("a3 comparado a a1 = " + a3.compareTo(a1)); + System.out.println("a3 comparado a a4 = " + a3.compareTo(a4)); + //System.out.println("Java esta roto en el manejo de excepciones!!!"); + } + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/CeroDenExc.java b/src/CeroDenExc.java new file mode 100644 index 0000000..4d3cdfc --- /dev/null +++ b/src/CeroDenExc.java @@ -0,0 +1,24 @@ + +public 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() + ")"; + } + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/ComparaAng.java b/src/ComparaAng.java new file mode 100644 index 0000000..3efbe9a --- /dev/null +++ b/src/ComparaAng.java @@ -0,0 +1,8 @@ + +public interface ComparaAng { + + public int compareTo(Angulo f); + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/ComparaFrac.java b/src/ComparaFrac.java new file mode 100644 index 0000000..9bba411 --- /dev/null +++ b/src/ComparaFrac.java @@ -0,0 +1,8 @@ + +public interface ComparaFrac { + + public int compareTo(Fraccion f); + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/Fraccion.java b/src/Fraccion.java index 7cf9d86..8bd3ec4 100644 --- a/src/Fraccion.java +++ b/src/Fraccion.java @@ -1,41 +1,5 @@ -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 implements OperFrac, ComparaFrac { private int num; private int den; @@ -124,23 +88,6 @@ class Fraccion implements OperFrac, ComparaFrac { 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!!!"); - } - } // vim: set et sw=4 sts=4 : diff --git a/src/FraccionTest.java b/src/FraccionTest.java new file mode 100644 index 0000000..ab4211e --- /dev/null +++ b/src/FraccionTest.java @@ -0,0 +1,23 @@ + +public class FraccionTest { + + // 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!!!"); + } + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/OperAng.java b/src/OperAng.java new file mode 100644 index 0000000..bac20ca --- /dev/null +++ b/src/OperAng.java @@ -0,0 +1,10 @@ + +public interface OperAng { + + public Angulo mas(Angulo f); + + public Angulo menos(Angulo f); + +} + +// vim: set et sw=4 sts=4 : diff --git a/src/OperFrac.java b/src/OperFrac.java new file mode 100644 index 0000000..ce357b8 --- /dev/null +++ b/src/OperFrac.java @@ -0,0 +1,10 @@ + +public interface OperFrac { + + public Fraccion mas(Fraccion f); + + public Fraccion menos(Fraccion f); + +} + +// vim: set et sw=4 sts=4 :