Probleme de compilation
sami
-
sami -
sami -
Bonjour,s'il vp aider moi pour resoudre ce probleme:
voici la class complexe
import java.math.*;
class Complexe implements Comparable {
private float x;
private float y;
public double calculModule(){
return Math.sqrt(x*x+y*y);
}
voici la methode inferieure qu'est defini ds l'interface Comparable et implementee ds la class Complexe
public boolean inferieur(Object o){
if(((Complexe)o).calculModule()<this.calculModule())
return true;
else
return false;
}
public boolean egal(Object o){
if(((Complexe)o.calculModule())==this.calculModule())
return true;
else
return false;
}
cannot resolve symbol
symbol : method sqrt (float)
location: class Math
return Math.sqrt(x*x+y*y);
^
inconvertible types
found : Object
required: Complexe
if(((Complexe)o).calculModule()<this.calculModule())
^
operator == cannot be applied to Complexe,double
if(((Complexe)o.calculModule())==this.calculModule())
^
je veu savoir pourquoi et donnez moi un autre solution pour implement ces methodes.
voici la class complexe
import java.math.*;
class Complexe implements Comparable {
private float x;
private float y;
public double calculModule(){
return Math.sqrt(x*x+y*y);
}
voici la methode inferieure qu'est defini ds l'interface Comparable et implementee ds la class Complexe
public boolean inferieur(Object o){
if(((Complexe)o).calculModule()<this.calculModule())
return true;
else
return false;
}
public boolean egal(Object o){
if(((Complexe)o.calculModule())==this.calculModule())
return true;
else
return false;
}
cannot resolve symbol
symbol : method sqrt (float)
location: class Math
return Math.sqrt(x*x+y*y);
^
inconvertible types
found : Object
required: Complexe
if(((Complexe)o).calculModule()<this.calculModule())
^
operator == cannot be applied to Complexe,double
if(((Complexe)o.calculModule())==this.calculModule())
^
je veu savoir pourquoi et donnez moi un autre solution pour implement ces methodes.
Configuration: Windows XP Firefox 2.0.0.6
3 réponses
-
Salut,
je sais pas si tu peux faire les opérations directement dans le paramètre de la fonction.
Dans ta classe Complexe, déclare un private float z, et ta fonction calculModule donnerait ça :
public double calculModule(float x, float y){
z=x*x+y*y;
return Math.sqrt(z);
} -
Autant pour moi, ta fonction donnerait plutot :
public double calculModule(){
z=x*x+y*y
return Math.sqrt(z);
} -
merci mais j'ai esseye comme vous dit ,et ca marche pas
et comment fair svp pour la fct inferieur (Object o)
j'ai vraiment besoin d'aide svp