11/11/09

Clase Numero Complejo - 2da parte



Se creo una "clase complejo" que tenia como proposito realizar las operaciones basicas de suma, resta, y multiplicacion de numeros complejos, ahora en este minitutorial realizaremos la implementacion de esta clase con Netbeans.

El codigo respectivo es este:

/*consola*/
import java.io.DataInputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
/*fin consola*/
/**
 * @author Mouse
 */
public class Main {

    public static void main(String[] args) {
        /*consola*/
        try {
            // TODO code application logic here
            //String linea;
            DataInputStream entrada = new DataInputStream(System.in);
            System.out.println("Ingrese real 1:");
            int re1 = Integer.parseInt(entrada.readLine());
            System.out.println("Ingrese img 1:");
            int im1 = Integer.parseInt(entrada.readLine());
            Complejo x = new Complejo(re1, im1);
            System.out.println("Ingrese real 2:");
            int re2 = Integer.parseInt(entrada.readLine());
            System.out.println("Ingrese img 2:");
            int im2 = Integer.parseInt(entrada.readLine());
            
            Complejo y = new Complejo(re2, im2);
            
            Complejo z = x.sumar(y);
            Complejo w = x.restar(y);
            Complejo v = x.multiplicar(y);
            
            System.out.println("Resultado Suma:" + z.getString());
            System.out.println("Resultado Resta:" + w.getString());
            System.out.println("Resultado Producto:" + v.getString());
            
        } catch (IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        /*fin consola*/
    }

}

No hay comentarios:

Publicar un comentario