Calcular distancia y pendiente de una recta
Publicado por pepe (15 intervenciones) el 02/03/2021 03:05:33
Tengo problemas para realizarlo no se como hacerle ya vi muchos videos pero en ninguno me sale ayuda :( no me salen errores pero si en el resultado
lo de arriba es del case
y aca esta el codigo de mi clase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
case 4:{
System.out.println("***Linea***");
System.out.println("Calcular la distancia y la pendiente de una recta");
System.out.println("Ingrese x1: ");
x1 = entrada.nextDouble();
System.out.println("Ingrese y1: ");
y1 = entrada.nextDouble();
System.out.println("Ingrese x2: ");
x2 = entrada.nextDouble();
System.out.println("Ingrese y2: ");
y2 = entrada.nextDouble();
linea_ADCS recta = new linea_ADCS(x1,x2,y1,y2);
System.out.println("La pendiente de la recta es: " + recta.pendiente());
System.out.println("La distancia entre ambos puntos es: " + recta.distancia());
}
y aca esta el codigo de mi clase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package figuras_adcs;
/**
*
* @author aryda
*/
public class linea_ADCS {
//propiedades de la clase
double x1,y1,x2,y2;
double D;
double M;
//constructor de la clase
public linea_ADCS(double cx1,double cy1,double cx2, double cy2){
this.x1 = cx1;
this.y1 = cy1;
this.x2 = cx2;
this.y2 = cy2;
}
//metodos de la clase
double distancia(){
D = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
return D;
}
double pendiente (){
M = (y1 - y2) / (x2 - x1);
return M;
}
}
Valora esta pregunta


0