Ciao a tutti,
sto facendo un esercizio sull'uso dell'ereditarietà, ma ottengo il seguente errore:
.\Punto3D.java:4: cannot find symbol
symbol : constructor Punto()
location : class Punto
public Punto3D(int x, int y, int z) {
Il codice:
TestDistanza.java
Codice PHP:
public class TestDistanza {
public static void main(String args[])
{
Punto p1 = new Punto(2, 4);
Punto p2 = new Punto(5, 6);
Punto3D p31 = new Punto3D(2, 4, 6);
Punto3D p32 = new Punto3D(5, 6, 7);
Double risultato1 = p1.calcolaDistanza(p2);
Double risultato2 = p31.calcolaDistanza3D(p32);
System.out.println(risultato1 + "\n");
System.out.println(risultato2 + "\n");
}
}
Punto.java
Codice PHP:
public class Punto {
private int x;
private int y;
private double distanza;
public Punto(int x, int y){
setXY(x, y);
}
public void setXY(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double calcolaDistanza(Punto p) {
double dy = y - p.getY();
double dx = y - p.getX();
return Math.sqrt(dy*dy + dx*dx);
}
}
Punto3D.java
Codice PHP:
public class Punto3D extends Punto {
private int z;
public Punto3D(int x, int y, int z) {
setXYZ(x, y, z);
}
public void setXYZ(int x, int y, int z) {
setXY(x, y);
this.z = z;
}
public int getZ() {
return z;
}
public double calcolaDistanza3D(Punto3D p) {
double dy = getY() - p.getY();
double dx = getX() - p.getX();
double dz = getZ() - p.getZ();
return Math.sqrt(dy*dy + dx*dx + dz*dz);
}
}
Grazie.