Problème "cannot find symbol" sous java
J2D2
-
J2D2 Messages postés 1 Date d'inscription Statut Membre Dernière intervention -
J2D2 Messages postés 1 Date d'inscription Statut Membre Dernière intervention -
Bonjour, a tous, alors voila, j'ai un gros problème; je vous explique, j'ai cours de programmation java, et le prof nous a donné des exercices, jusque la, tout va bien, sauf que voila, j'ai passé un temps monstre sur un de ses exercices, sans trouver mon erreur, le voici :
public class Rectangle {
//Attributs
private Point coinSupGauche;
private Point coinInfDroit;
//Constructeurs
public Rectangle(Point coinSupGauche,Point coinInfDroit) {
if (coinSupGauche.estAGauche(coinInfDroit)&&
coinSupGauche.estEnHaut(coinInfDroit));{
throw new
System.out.println("ce point n'est pas a gauche et en haut du coin inferieur droit");
}
this.coinSupGauche=coinSupGauche;
this.coinInfDroit=coinInfDroit;
}
//Setter
public void setAbsCoinDroit (double AbsCoinDroit){
coinInfDroit.abs=AbsCoinDroit;
}
public void setOrdCoinDroit (double OrdCoinDroit){
coinInfDroit.ord=OrdCoinDroit;
}
public void setAbsCoinGauche (double AbsCoinGauche){
coinSupGauche.abs=AbsCoinGauche;
}
public void setOrdCoinGauche (double OrdCoinGauche){
coinSupGauche.abs=OrdCoinGauche;
}
//Getter
public Point getcoinSupGauche(){
return coinSupGauche;
}
public Point getcoinInfDroit(){
return coinInfDroit;
}
//Methode toString
public String toString(){
String result;
result="[SG="+coinSupGauche+" ID="+coinInfDroit+"]";
return result;
}
//Methode estCompritDans
public boolean estCompritDans(Point unPoint){
return (coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord);
}
//Methode estSurLeBord
public boolean estSurLeBord(Point unPoint){
boolean estSurLeBord=false;
if ((coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && unPoint.ord==coinSupGauche.ord)||(coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && unPoint.ord==coinInfDroit.ord)||(coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord && unPoint.abs==coinSupGauche.abs)||(coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord && unPoint.abs==coinInfDroit.abs));
estSurLeBord=true;
return estSurLeBord;}
}
je déclare les attributs comme des points, la aucun soucis, j'ai bien créer la classe "Point" au préalable (celle-ci passe sans soucis) mais voila, quand je compile ma classe rectangle, il me met "cannot find symbol class Point" à la ligne 3,31,34,44 et 48, je ne comprend vraiment pas, en plus, il me met "cannot find symbol class out" pour la ligne 10.
savez vous me dire se qui cloche la dedans svp, merci d'avance
public class Rectangle {
//Attributs
private Point coinSupGauche;
private Point coinInfDroit;
//Constructeurs
public Rectangle(Point coinSupGauche,Point coinInfDroit) {
if (coinSupGauche.estAGauche(coinInfDroit)&&
coinSupGauche.estEnHaut(coinInfDroit));{
throw new
System.out.println("ce point n'est pas a gauche et en haut du coin inferieur droit");
}
this.coinSupGauche=coinSupGauche;
this.coinInfDroit=coinInfDroit;
}
//Setter
public void setAbsCoinDroit (double AbsCoinDroit){
coinInfDroit.abs=AbsCoinDroit;
}
public void setOrdCoinDroit (double OrdCoinDroit){
coinInfDroit.ord=OrdCoinDroit;
}
public void setAbsCoinGauche (double AbsCoinGauche){
coinSupGauche.abs=AbsCoinGauche;
}
public void setOrdCoinGauche (double OrdCoinGauche){
coinSupGauche.abs=OrdCoinGauche;
}
//Getter
public Point getcoinSupGauche(){
return coinSupGauche;
}
public Point getcoinInfDroit(){
return coinInfDroit;
}
//Methode toString
public String toString(){
String result;
result="[SG="+coinSupGauche+" ID="+coinInfDroit+"]";
return result;
}
//Methode estCompritDans
public boolean estCompritDans(Point unPoint){
return (coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord);
}
//Methode estSurLeBord
public boolean estSurLeBord(Point unPoint){
boolean estSurLeBord=false;
if ((coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && unPoint.ord==coinSupGauche.ord)||(coinSupGauche.abs<=unPoint.abs && unPoint.abs<=coinInfDroit.abs && unPoint.ord==coinInfDroit.ord)||(coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord && unPoint.abs==coinSupGauche.abs)||(coinInfDroit.ord<=unPoint.ord && unPoint.ord<=coinSupGauche.ord && unPoint.abs==coinInfDroit.abs));
estSurLeBord=true;
return estSurLeBord;}
}
je déclare les attributs comme des points, la aucun soucis, j'ai bien créer la classe "Point" au préalable (celle-ci passe sans soucis) mais voila, quand je compile ma classe rectangle, il me met "cannot find symbol class Point" à la ligne 3,31,34,44 et 48, je ne comprend vraiment pas, en plus, il me met "cannot find symbol class out" pour la ligne 10.
savez vous me dire se qui cloche la dedans svp, merci d'avance
A voir également:
- Problème "cannot find symbol" sous java
- Waptrick java football - Télécharger - Jeux vidéo
- Jeux java itel - Télécharger - Jeux vidéo
- Eclipse java - Télécharger - Langages
- Java apk - Télécharger - Langages
- Waptrick java voiture - Télécharger - Jeux vidéo
6 réponses
Edit : la première erreure, a savoir :"cannot find symbol class Point" a été réglée, néanmoins la deuxième persiste, aidez moi svp, je n'en peux plus
Bonsoir, Marco la baraque, tout d'abords, merci beaucoup pour ton aide, mais voila mon petit problème : je comprend +/- ta remarque (je vais la relire une ou deux fois pour bien etre sur de la comprendre a 100%) mais alors comment faire? mon prof nous avait montré les Try Catch ... le problème est que je ne sais pas comment l'ecrire ici, j'ai essayer quelque chose :
//Constructeur
public Rectangle (Point coinSupGauche, Point coinInfDroit){
try {coinSupGauche.estAGauche(coinInfDroit); coinSupGauche.estEnHaut(coinInfDroit);
}
catch (Excepetion e){
System.out.println("Ce point n'est pas à gauche et en gaut du coin Inférieur Droit");}
}
this.coinSupGauche=coinSupGauche;
this.coinInfDroit=coinInfDroit;
}
seulement voila, il me met des erreurs à toutes les lignes ou j'utilise les variables "coinSupGauche" et "coinInfDroit", et puis des erreures du genre "illegal start of type" pour la ligne 15 et 16 (donc les deux "this."). a l'aide stp, je ne m'en sort vraiment plus :(
//Constructeur
public Rectangle (Point coinSupGauche, Point coinInfDroit){
try {coinSupGauche.estAGauche(coinInfDroit); coinSupGauche.estEnHaut(coinInfDroit);
}
catch (Excepetion e){
System.out.println("Ce point n'est pas à gauche et en gaut du coin Inférieur Droit");}
}
this.coinSupGauche=coinSupGauche;
this.coinInfDroit=coinInfDroit;
}
seulement voila, il me met des erreurs à toutes les lignes ou j'utilise les variables "coinSupGauche" et "coinInfDroit", et puis des erreures du genre "illegal start of type" pour la ligne 15 et 16 (donc les deux "this."). a l'aide stp, je ne m'en sort vraiment plus :(
alors, j'ai bien relu ton message, je pense l'avoir comprit complètement, mais comment fait tu ta classe? pourrait tu me la mettre stp?? je sais que sa serait plutôt a moi de la faire, et je jure de m'y mettre, mais comme sa j'ai la réponse, merci d'avance
le bloc try...catch il serait plutot quand tu appelles le constructeur...
la tu cherche a levé une exception dans le constructeur pour ça il te faudrait deja faire une classe avec ta nouvelle exception
la tu cherche a levé une exception dans le constructeur pour ça il te faudrait deja faire une classe avec ta nouvelle exception
public class pasGauchePasHautException extends Exception{}ensuite dans ton contructeur tu leve une exception en cas de probleme avec un throws
public Rectangle(Point coinSupGauche,Point coinInfDroit) throws pasGauchePasHautException { if (coinSupGauche.estAGauche(coinInfDroit)&& coinSupGauche.estEnHaut(coinInfDroit)) throw new pasGauchePasHautException(); this.coinSupGauche=coinSupGauche; this.coinInfDroit=coinInfDroit; }et mainttenant quand tu vas appellé le constructeur tu utiliseras le bloc try...catch comme ça
try{ Rectangle r = new Rectangle(Point coinSupGauche,Point coinInfDroit);} catch(pasGauchePasHautException e) {System.out.println("ce point n'est pas a gauche et en haut du coin inferieur droit");}
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question
Voilà, c'est exactement comme Mype l'a expliqué.
La seule modification que j'aurais apporté aurait été de définir le message d'erreur directement dans la classe d'exception :
Et comme ça, dans ton catch, tu as juste à faire un System.out.println(e.getMessage()); quelque soit le type d'exception que tu catches.
Cordialement,
La seule modification que j'aurais apporté aurait été de définir le message d'erreur directement dans la classe d'exception :
public class pasGauchePasHautException extends Exception { private static String msg = "ce point n'est pas a gauche et en haut du coin inferieur droit"; public String getMessage() { return msg; } }
Et comme ça, dans ton catch, tu as juste à faire un System.out.println(e.getMessage()); quelque soit le type d'exception que tu catches.
Cordialement,
Tu ne peux pas faire
throw new
System.out.println("ce point n'est pas a gauche et en haut du coin inferieur droit");
Le mot clé throw permet de lancer une nouvelle exception, ce n'est pas ce que tu fais ici.
Soit tu écris simplement System.out.println("ce point n'est pas a gauche et en haut du coin inferieur droit"); , soit tu lances une exception : throw new Exception(); (en principe on le lève jamais une exception du type Exception, mais c'est pour l'exemple).
Personnellement, je créerais une classe qui étend Exception et dont le message d'erreur (message retourné par getMessage()) est celui que tu veux afficher. De cette manière tu pourras lever une telle exception.
Cordialement,