Problema con un contructor
Publicado por Yago (8 intervenciones) el 11/11/2020 23:26:29
Buenas, como siempre tengo mis lios grandes y hoy es con un constructor.
Tengo el siguiente código, y el problema viene con
No entiendo por qué no coge los datos de p1 T__TT
Tengo el siguiente código, y el problema viene con
1
Punto2D p2 = new Punto2D(p1);
No entiendo por qué no coge los datos de p1 T__TT
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package tema3;
public class Punto2D {
private double cx;
private double cy;
public Punto2D() {
cx = 0.0;
cy = 0.0;
}
public Punto2D(double x, double y) {
cx=x;
cy=y;
this.cx = cx;
this.cy = cy;
}
public double getX() {
return cx;
}
public void setX(double x) {
this.cx = x;
}
public double getY() {
return cy;
}
public void setY(double y) {
this.cy = y;
}
public void flip(){
this.cx = cy;
this.cy = cx;
}
double dist(Punto2D p){
return Math.sqrt(Math.pow(p.cx - this.cx, 2) + Math.pow(p.cy - this.cy, 2));
}
double manhattanDist(Punto2D p){
return Math.abs(p.cx - this.cx) + Math.abs(p.cy - this.cy);
}
double slope (Punto2D p){
return (p.cy - this.cy)/(p.cx - this.cx);
}
@Override
public String toString() {
return "Punto2D[" + cx + "," + cy + ']';
}
public static void main(String[]args){
Punto2D p1 = new Punto2D(4.5, 5.5);
Punto2D p2 = new Punto2D(p1);
System.out.println(p2);
}
}
Valora esta pregunta


0