apoyenme por favor a convertirlo a java este programa!!
// USO DE UNA FUNCION VIRTUAL PARA DEFINIR UNA INTERFAZ.
#include <iostream.h>
class area{
double dim1, dim2; //dimensiones de la figura
public:
void estableceDims(double d1, double d2){
dim1 = d1;
dim2 = d2;
}
void obtenDims(double &d1, double &d2){
d1 = dim1;
d2 = dim2;
}
virtual double obtenArea(){
cout << "Usted debe redefinir esta funci¢nn";
return 0.0;
}
};
class rectangulo : public area{
public:
double obtenArea(){
double d1, d2;
obtenDims(d1, d2);
return d1*d2;
}
};
class triangulo : public area{
public:
double obtenArea(){
double d1, d2;
obtenDims(d1,d2);
return 0.5*d1*d2;
}
};
main(){
area *p;
rectangulo r;
triangulo t;
r.estableceDims(3.0,4.0);
t.estableceDims(4.0,5.0);
p = &r;
cout << "El area del rectangulo es : " << p->obtenArea() << "n";
p = &t;
cout << "El area del traingulo es : " << p->obtenArea() << "n";
return 0;
}
#include <iostream.h>
class area{
double dim1, dim2; //dimensiones de la figura
public:
void estableceDims(double d1, double d2){
dim1 = d1;
dim2 = d2;
}
void obtenDims(double &d1, double &d2){
d1 = dim1;
d2 = dim2;
}
virtual double obtenArea(){
cout << "Usted debe redefinir esta funci¢nn";
return 0.0;
}
};
class rectangulo : public area{
public:
double obtenArea(){
double d1, d2;
obtenDims(d1, d2);
return d1*d2;
}
};
class triangulo : public area{
public:
double obtenArea(){
double d1, d2;
obtenDims(d1,d2);
return 0.5*d1*d2;
}
};
main(){
area *p;
rectangulo r;
triangulo t;
r.estableceDims(3.0,4.0);
t.estableceDims(4.0,5.0);
p = &r;
cout << "El area del rectangulo es : " << p->obtenArea() << "n";
p = &t;
cout << "El area del traingulo es : " << p->obtenArea() << "n";
return 0;
}