Primer ejercicio POO 2013

February 11, 2013 por M.A. D. N. Jose Gallardo   Comentarios (0)

, , ,

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package distancia;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;



/**
*
* @author LAPDTIC
*/
public class Distancia {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Integer x1, x2, y1, y2;
Double distancia = 0.0;

x1=leeEntero("x1");
y1=leeEntero("y1");
x2=leeEntero("x2");
y2=leeEntero("y2");

distancia=Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2))/2;
System.out.println("Distancia "+ distancia.toString());
}

private static Integer leeEntero(String msg) {
System.out.println(msg);
Integer i = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
i = Integer.parseInt(br.readLine());
} catch (IOException ex) {
Logger.getLogger(Distancia.class.getName()).log(Level.SEVERE, null, ex);
}
return i;
}
}