Probleme prog java
ddou03
Messages postés
60
Date d'inscription
Statut
Membre
Dernière intervention
-
scriptiz Messages postés 1424 Date d'inscription Statut Membre Dernière intervention -
scriptiz Messages postés 1424 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
J'ai créé un prog en java (eclipse) qui permet de calculer le GPA d'une moyenne de notes sur le système américain (les notes sont des lettres : A , B , ...F pour ceux qui ne connaissent pas).
Il fonctionne parfaitement seulement j'aimerais y apporter qq modifs :
1) A l'ppel du prog ,je demande à l'utilisateur de donner sa note, mais de manière chiffrée : 0->4 tous les 0.5.
J'aimerais directement donner la lettre
2) Réduire le résultat à 2 chiffres après la virgule ( approxim du style 2.5359152->2.54 ; 2.4932511->2.49)
Ps : pouvez-vous me donner l'astuce pour insérer mon code dans un message (à part copier coller)
Merci par avance de vos réponses
J'ai créé un prog en java (eclipse) qui permet de calculer le GPA d'une moyenne de notes sur le système américain (les notes sont des lettres : A , B , ...F pour ceux qui ne connaissent pas).
Il fonctionne parfaitement seulement j'aimerais y apporter qq modifs :
1) A l'ppel du prog ,je demande à l'utilisateur de donner sa note, mais de manière chiffrée : 0->4 tous les 0.5.
J'aimerais directement donner la lettre
2) Réduire le résultat à 2 chiffres après la virgule ( approxim du style 2.5359152->2.54 ; 2.4932511->2.49)
Ps : pouvez-vous me donner l'astuce pour insérer mon code dans un message (à part copier coller)
Merci par avance de vos réponses
A voir également:
- Probleme prog 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
4 réponses
Pour mettre ton code dans un message tu dois utiliser la balise <code >ton code</code> ainsi tu garder l'indentation, ...
Sinon pour tes deux questions :
1) J'ai pas bien compris ta question, sinon pour lire une côte tu peux utiliser quelque chose comme ça :
Tu peux faire plus simple en mettant un petit "java.util.*" en haut de ton fichier pour la déclaration du scanner.
2) Voici une fonction pour réduire un nombre à x chiffres après les virgules :
Donc si tu l'appelle comme ceci :
Tu auras 3.14 en sortie.
Sinon pour tes deux questions :
1) J'ai pas bien compris ta question, sinon pour lire une côte tu peux utiliser quelque chose comme ça :
java.util.Scanner sc = new java.util.Scanner(System.in); double maQuote = sc.nextDouble(); System.out.println(maQuote);
Tu peux faire plus simple en mettant un petit "java.util.*" en haut de ton fichier pour la déclaration du scanner.
2) Voici une fonction pour réduire un nombre à x chiffres après les virgules :
public static double arrondir(double nombre, int precision) { int temp = (int)(nombre * Math.pow(10,precision)); return ((double)temp)/Math.pow(10,precision); }
Donc si tu l'appelle comme ceci :
double piArrondi = arrondir(3.14159457, 2); System.out.println(piArrondi);
Tu auras 3.14 en sortie.
bonjour, merci pour la fct de précision de décimales.
Voici mon code : désolé il est long et peu efficace, mais c'est la seule méthose que j'ai trouvée pour le moment.
Le problème que je veux à tout prix régler: Lorsque le programme demande la note, il faut saisir une lettre qui doit correspondre au bon coefficient( 0, 2, 2.5, 3, 3.5, 4).
<code>public class CalculGPA {
public static float calcul(float noteMath, float notePhysique,
float noteAutom, float noteInfo, float noteSsg, float noteLv,
float noteApa, float noteEntreprise, float noteSport) {
return (float) (((noteMath * 7.5) + (notePhysique * 7.5)
+ (noteAutom * 7.5) + (noteInfo * 7.5) + (noteSsg * 7.5)
+ (noteLv * 7.5) + (noteApa * 7.5) + (noteEntreprise) * 2 + (noteSport * 4)) / (58.5));
}
public static void main(String[] args) {
System.out.println("+-------------------------------------+"+
"\n"+"|"+" "+"|"+"\n"+
"|"+" ! CALCUL DU GPA ! "+"|"+"\n"+"|"+
" "+"|"+"\n"+
"+-------------------------------------+"+"\n"+"\n");
System.out.println("Quelle est votre note en Math ?");
float noteMath = Clavier.lireFloat();
if(noteMath==4){
System.out.println("(A)");
}
else{
if(noteMath==3.5){
System.out.println("(B)");
}
else{
if(noteMath==3){
System.out.println("(C)");
}
else{
if(noteMath==2.5){
System.out.println("(D)");
}
else{
if(noteMath==2){
System.out.println("(E)");
}
else{
if(noteMath==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Physique ?");
float notePhysique = Clavier.lireFloat();
if(notePhysique==4){
System.out.println("(A)");
}
else{
if(notePhysique==3.5){
System.out.println("(B)");
}
else{
if(notePhysique==3){
System.out.println("(C)");
}
else{
if(notePhysique==2.5){
System.out.println("(D)");
}
else{
if(notePhysique==2){
System.out.println("(E)");
}
else{
if(notePhysique==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Automatique ?");
float noteAutom = Clavier.lireFloat();
if(noteAutom==4){
System.out.println("(A)");
}
else{
if(noteAutom==3.5){
System.out.println("(B)");
}
else{
if(noteAutom==3){
System.out.println("(C)");
}
else{
if(noteAutom==2.5){
System.out.println("(D)");
}
else{
if(noteAutom==2){
System.out.println("(E)");
}
else{
if(noteAutom==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Informatique ?");
float noteInfo = Clavier.lireFloat();
if(noteInfo==4){
System.out.println("(A)");
}
else{
if(noteInfo==3.5){
System.out.println("(B)");
}
else{
if(noteInfo==3){
System.out.println("(C)");
}
else{
if(noteInfo==2.5){
System.out.println("(D)");
}
else{
if(noteInfo==2){
System.out.println("(E)");
}
else{
if(noteInfo==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en SSG ?");
float noteSsg = Clavier.lireFloat();
if(noteSsg==4){
System.out.println("(A)");
}
else{
if(noteSsg==3.5){
System.out.println("(B)");
}
else{
if(noteSsg==3){
System.out.println("(C)");
}
else{
if(noteSsg==2.5){
System.out.println("(D)");
}
else{
if(noteSsg==2){
System.out.println("(E)");
}
else{
if(noteSsg==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en LV ?");
float noteLv = Clavier.lireFloat();
if(noteLv==4){
System.out.println("(A)");
}
else{
if(noteLv==3.5){
System.out.println("(B)");
}
else{
if(noteLv==3){
System.out.println("(C)");
}
else{
if(noteLv==2.5){
System.out.println("(D)");
}
else{
if(noteLv==2){
System.out.println("(E)");
}
else{
if(noteLv==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Apa ?");
float noteApa = Clavier.lireFloat();
if(noteApa==4){
System.out.println("(A)");
}
else{
if(noteApa==3.5){
System.out.println("(B)");
}
else{
if(noteApa==3){
System.out.println("(C)");
}
else{
if(noteApa==2.5){
System.out.println("(D)");
}
else{
if(noteApa==2){
System.out.println("(E)");
}
else{
if(noteApa==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Entreprise ?");
float noteEntreprise = Clavier.lireFloat();
if(noteEntreprise==4){
System.out.println("(A)");
}
else{
if(noteEntreprise==3.5){
System.out.println("(B)");
}
else{
if(noteEntreprise==3){
System.out.println("(C)");
}
else{
if(noteEntreprise==2.5){
System.out.println("(D)");
}
else{
if(noteEntreprise==2){
System.out.println("(E)");
}
else{
if(noteEntreprise==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Sport ?");
float noteSport = Clavier.lireFloat();
if(noteSport==4){
System.out.println("(A)");
}
else{
if(noteSport==3.5){
System.out.println("(B)");
}
else{
if(noteSport==3){
System.out.println("(C)");
}
else{
if(noteSport==2.5){
System.out.println("(D)");
}
else{
if(noteSport==2){
System.out.println("(E)");
}
else{
if(noteSport==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Votre GPA est : "
+ calcul(noteMath, notePhysique, noteAutom, noteInfo, noteSsg,
noteLv, noteApa, noteEntreprise, noteSport));
}
}
<code>
Merci!
Voici mon code : désolé il est long et peu efficace, mais c'est la seule méthose que j'ai trouvée pour le moment.
Le problème que je veux à tout prix régler: Lorsque le programme demande la note, il faut saisir une lettre qui doit correspondre au bon coefficient( 0, 2, 2.5, 3, 3.5, 4).
<code>public class CalculGPA {
public static float calcul(float noteMath, float notePhysique,
float noteAutom, float noteInfo, float noteSsg, float noteLv,
float noteApa, float noteEntreprise, float noteSport) {
return (float) (((noteMath * 7.5) + (notePhysique * 7.5)
+ (noteAutom * 7.5) + (noteInfo * 7.5) + (noteSsg * 7.5)
+ (noteLv * 7.5) + (noteApa * 7.5) + (noteEntreprise) * 2 + (noteSport * 4)) / (58.5));
}
public static void main(String[] args) {
System.out.println("+-------------------------------------+"+
"\n"+"|"+" "+"|"+"\n"+
"|"+" ! CALCUL DU GPA ! "+"|"+"\n"+"|"+
" "+"|"+"\n"+
"+-------------------------------------+"+"\n"+"\n");
System.out.println("Quelle est votre note en Math ?");
float noteMath = Clavier.lireFloat();
if(noteMath==4){
System.out.println("(A)");
}
else{
if(noteMath==3.5){
System.out.println("(B)");
}
else{
if(noteMath==3){
System.out.println("(C)");
}
else{
if(noteMath==2.5){
System.out.println("(D)");
}
else{
if(noteMath==2){
System.out.println("(E)");
}
else{
if(noteMath==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Physique ?");
float notePhysique = Clavier.lireFloat();
if(notePhysique==4){
System.out.println("(A)");
}
else{
if(notePhysique==3.5){
System.out.println("(B)");
}
else{
if(notePhysique==3){
System.out.println("(C)");
}
else{
if(notePhysique==2.5){
System.out.println("(D)");
}
else{
if(notePhysique==2){
System.out.println("(E)");
}
else{
if(notePhysique==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Automatique ?");
float noteAutom = Clavier.lireFloat();
if(noteAutom==4){
System.out.println("(A)");
}
else{
if(noteAutom==3.5){
System.out.println("(B)");
}
else{
if(noteAutom==3){
System.out.println("(C)");
}
else{
if(noteAutom==2.5){
System.out.println("(D)");
}
else{
if(noteAutom==2){
System.out.println("(E)");
}
else{
if(noteAutom==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Informatique ?");
float noteInfo = Clavier.lireFloat();
if(noteInfo==4){
System.out.println("(A)");
}
else{
if(noteInfo==3.5){
System.out.println("(B)");
}
else{
if(noteInfo==3){
System.out.println("(C)");
}
else{
if(noteInfo==2.5){
System.out.println("(D)");
}
else{
if(noteInfo==2){
System.out.println("(E)");
}
else{
if(noteInfo==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en SSG ?");
float noteSsg = Clavier.lireFloat();
if(noteSsg==4){
System.out.println("(A)");
}
else{
if(noteSsg==3.5){
System.out.println("(B)");
}
else{
if(noteSsg==3){
System.out.println("(C)");
}
else{
if(noteSsg==2.5){
System.out.println("(D)");
}
else{
if(noteSsg==2){
System.out.println("(E)");
}
else{
if(noteSsg==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en LV ?");
float noteLv = Clavier.lireFloat();
if(noteLv==4){
System.out.println("(A)");
}
else{
if(noteLv==3.5){
System.out.println("(B)");
}
else{
if(noteLv==3){
System.out.println("(C)");
}
else{
if(noteLv==2.5){
System.out.println("(D)");
}
else{
if(noteLv==2){
System.out.println("(E)");
}
else{
if(noteLv==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Apa ?");
float noteApa = Clavier.lireFloat();
if(noteApa==4){
System.out.println("(A)");
}
else{
if(noteApa==3.5){
System.out.println("(B)");
}
else{
if(noteApa==3){
System.out.println("(C)");
}
else{
if(noteApa==2.5){
System.out.println("(D)");
}
else{
if(noteApa==2){
System.out.println("(E)");
}
else{
if(noteApa==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Entreprise ?");
float noteEntreprise = Clavier.lireFloat();
if(noteEntreprise==4){
System.out.println("(A)");
}
else{
if(noteEntreprise==3.5){
System.out.println("(B)");
}
else{
if(noteEntreprise==3){
System.out.println("(C)");
}
else{
if(noteEntreprise==2.5){
System.out.println("(D)");
}
else{
if(noteEntreprise==2){
System.out.println("(E)");
}
else{
if(noteEntreprise==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Quelle est votre note en Sport ?");
float noteSport = Clavier.lireFloat();
if(noteSport==4){
System.out.println("(A)");
}
else{
if(noteSport==3.5){
System.out.println("(B)");
}
else{
if(noteSport==3){
System.out.println("(C)");
}
else{
if(noteSport==2.5){
System.out.println("(D)");
}
else{
if(noteSport==2){
System.out.println("(E)");
}
else{
if(noteSport==0){
System.out.println("(FX)");
}
else{
System.out.println("Veuillez recommencer");
}
}
}
}
}
}
System.out.println("Votre GPA est : "
+ calcul(noteMath, notePhysique, noteAutom, noteInfo, noteSsg,
noteLv, noteApa, noteEntreprise, noteSport));
}
}
<code>
Merci!
Désolé je me suis planté!
public class CalculGPA { public static float calcul(float noteMath, float notePhysique, float noteAutom, float noteInfo, float noteSsg, float noteLv, float noteApa, float noteEntreprise, float noteSport) { return (float) (((noteMath * 7.5) + (notePhysique * 7.5) + (noteAutom * 7.5) + (noteInfo * 7.5) + (noteSsg * 7.5) + (noteLv * 7.5) + (noteApa * 7.5) + (noteEntreprise) * 2 + (noteSport * 4)) / (58.5)); } public static void main(String[] args) { System.out.println("+-------------------------------------+"+ "\n"+"|"+" "+"|"+"\n"+ "|"+" ! CALCUL DU GPA ! "+"|"+"\n"+"|"+ " "+"|"+"\n"+ "+-------------------------------------+"+"\n"+"\n"); System.out.println("Quelle est votre note en Math ?"); float noteMath = Clavier.lireFloat(); if(noteMath==4){ System.out.println("(A)"); } else{ if(noteMath==3.5){ System.out.println("(B)"); } else{ if(noteMath==3){ System.out.println("(C)"); } else{ if(noteMath==2.5){ System.out.println("(D)"); } else{ if(noteMath==2){ System.out.println("(E)"); } else{ if(noteMath==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Physique ?"); float notePhysique = Clavier.lireFloat(); if(notePhysique==4){ System.out.println("(A)"); } else{ if(notePhysique==3.5){ System.out.println("(B)"); } else{ if(notePhysique==3){ System.out.println("(C)"); } else{ if(notePhysique==2.5){ System.out.println("(D)"); } else{ if(notePhysique==2){ System.out.println("(E)"); } else{ if(notePhysique==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Automatique ?"); float noteAutom = Clavier.lireFloat(); if(noteAutom==4){ System.out.println("(A)"); } else{ if(noteAutom==3.5){ System.out.println("(B)"); } else{ if(noteAutom==3){ System.out.println("(C)"); } else{ if(noteAutom==2.5){ System.out.println("(D)"); } else{ if(noteAutom==2){ System.out.println("(E)"); } else{ if(noteAutom==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Informatique ?"); float noteInfo = Clavier.lireFloat(); if(noteInfo==4){ System.out.println("(A)"); } else{ if(noteInfo==3.5){ System.out.println("(B)"); } else{ if(noteInfo==3){ System.out.println("(C)"); } else{ if(noteInfo==2.5){ System.out.println("(D)"); } else{ if(noteInfo==2){ System.out.println("(E)"); } else{ if(noteInfo==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en SSG ?"); float noteSsg = Clavier.lireFloat(); if(noteSsg==4){ System.out.println("(A)"); } else{ if(noteSsg==3.5){ System.out.println("(B)"); } else{ if(noteSsg==3){ System.out.println("(C)"); } else{ if(noteSsg==2.5){ System.out.println("(D)"); } else{ if(noteSsg==2){ System.out.println("(E)"); } else{ if(noteSsg==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en LV ?"); float noteLv = Clavier.lireFloat(); if(noteLv==4){ System.out.println("(A)"); } else{ if(noteLv==3.5){ System.out.println("(B)"); } else{ if(noteLv==3){ System.out.println("(C)"); } else{ if(noteLv==2.5){ System.out.println("(D)"); } else{ if(noteLv==2){ System.out.println("(E)"); } else{ if(noteLv==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Apa ?"); float noteApa = Clavier.lireFloat(); if(noteApa==4){ System.out.println("(A)"); } else{ if(noteApa==3.5){ System.out.println("(B)"); } else{ if(noteApa==3){ System.out.println("(C)"); } else{ if(noteApa==2.5){ System.out.println("(D)"); } else{ if(noteApa==2){ System.out.println("(E)"); } else{ if(noteApa==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Entreprise ?"); float noteEntreprise = Clavier.lireFloat(); if(noteEntreprise==4){ System.out.println("(A)"); } else{ if(noteEntreprise==3.5){ System.out.println("(B)"); } else{ if(noteEntreprise==3){ System.out.println("(C)"); } else{ if(noteEntreprise==2.5){ System.out.println("(D)"); } else{ if(noteEntreprise==2){ System.out.println("(E)"); } else{ if(noteEntreprise==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Quelle est votre note en Sport ?"); float noteSport = Clavier.lireFloat(); if(noteSport==4){ System.out.println("(A)"); } else{ if(noteSport==3.5){ System.out.println("(B)"); } else{ if(noteSport==3){ System.out.println("(C)"); } else{ if(noteSport==2.5){ System.out.println("(D)"); } else{ if(noteSport==2){ System.out.println("(E)"); } else{ if(noteSport==0){ System.out.println("(FX)"); } else{ System.out.println("Veuillez recommencer"); } } } } } } System.out.println("Votre GPA est : " + calcul(noteMath, notePhysique, noteAutom, noteInfo, noteSsg, noteLv, noteApa, noteEntreprise, noteSport)); } }