From f9ae0eb22d1b5e8b12030d43c77c634c81743e73 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Tue, 2 May 2006 19:14:33 +0000 Subject: [PATCH 1/1] =?utf8?q?Refactoriza=20clases=20de=20Angulo=20y=20Fra?= =?utf8?q?ccion.=20Separa=20las=20clases/interfaces=20auxiliares=20de=20An?= =?utf8?q?gulo=20y=20Fraccion,=20cada=20una=20en=20su=20propio=20archivo,?= =?utf8?q?=20para=20que=20sigan=20la=20Java-way.=20Tambi=C3=A9n=20se=20sac?= =?utf8?q?a=20para=20afuera=20los=20tests=20que=20tienen=20sus=20propias?= =?utf8?q?=20clases.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/Angulo.java | 16 +------------ src/AnguloTest.java | 23 ++++++++++++++++++ src/CeroDenExc.java | 24 +++++++++++++++++++ src/ComparaAng.java | 8 +++++++ src/ComparaFrac.java | 8 +++++++ src/Fraccion.java | 55 +------------------------------------------ src/FraccionTest.java | 23 ++++++++++++++++++ src/OperAng.java | 10 ++++++++ src/OperFrac.java | 10 ++++++++ 9 files changed, 108 insertions(+), 69 deletions(-) create mode 100644 src/AnguloTest.java create mode 100644 src/CeroDenExc.java create mode 100644 src/ComparaAng.java create mode 100644 src/ComparaFrac.java create mode 100644 src/FraccionTest.java create mode 100644 src/OperAng.java create mode 100644 src/OperFrac.java 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 : -- 2.43.0