1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
| import java.util.Scanner;
public class Etudiant implements Comparable {
String prenom, nom, codePermanent;
double moyenneCumul; //(entre 0 et 4.3)
int credits, identifiant;
//Constructeur
public Etudiant(int id, String prenom, String nom, String codeperm, double moyenne, int credits )
{
identifiant = id;
this.prenom = prenom;
this.nom = nom;
codePermanent = codeperm;
moyenneCumul = moyenne;
this.credits = credits;
}
// Ajout de crédit pour la session en cours
public int addcredit ( )
{
Scanner scan = new Scanner (System.in);
System.out.println("Entrez le nbr de crédit obtenu pour cette session: ");
int ajoutcredits = scan.nextInt();
credits = credits + ajoutcredits;
return credits;
}
// Accéder au crédit
public int getcredit ( )
{
return credits;
}
// Accéder à la moyenne
public double getmoyenneCumul ( )
{
return moyenneCumul;
}
// méthode toString
public String toString()
{
return "Id: " + identifiant +
"\tPrénom: " + prenom +
"\t Nom: " + nom +
"\t Code Permanent: " + codePermanent +
"\t Moyenne cumulative: " + moyenneCumul +
"\t Crédits: " + credits;
}
// préséance d'un nom par rapport à un autre
public int compareTo(Object arg0)
{
int rest=this.nom.compareToIgnoreCase(((Etudiant)arg0).nom);
if (rest > 0)
System.out.println("Le nom 1 vient en premier");
else
if (rest == 0)
System.out.println("Le nom 1 vient à égalité");
else
System.out.println("Le nom 1 vient après");
return rest;
}
// comparaison d'un nom par rapport à un autrE
public boolean equals(Object arg0)
{
if (this.nom.equals(((Etudiant)arg0).nom))
System.out.println("Personne avec le même nom");
else
System.out.println("Personne avec un nom différend");
return this.nom.equals(((Etudiant)arg0).nom);
}
}
//////******** Main ********//////
import java.util.Scanner;
public class TesteurEtudiant {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int comp01, choix;
boolean rep01, rep02, rep03, rep04, rep05, rep06;
double moy;
Etudiant etud01 = new Etudiant(1, "Luc", "Lapointe", "lapj30027802", 0.2, 0);
Etudiant etud02 = new Etudiant(2, "Jeanne", "Taillon", "taij05127709", 4.2, 9);
Etudiant etud03 = new Etudiant(3, "Zoe", "Lapointe", "bisl13067909", 3.0, 19);
do
{
Scanner scan = new Scanner (System.in);
System.out.println(etud01);
System.out.println(etud02);
System.out.println(etud03);
System.out.println("Que désirez-vous faire?");
System.out.println("1) Ajouter des crédits");
System.out.println("2) Vérifier la préséance d'un nom");
System.out.println("3) Comparer 2 noms");
System.out.println("4) Voir la moyenne cumulative");
System.out.println("5) Quitter");
choix = scan.nextInt();
// 1) Ajouter des crédits
if ( choix == 1)
{
System.out.println("Entrez l'identifiant de l'étudiant : ");
int id = scan.nextInt();
if (id == 1)
{
etud01.addcredit();
}
else if (id == 2)
{
etud02.addcredit();
}
else if (id == 2)
{
etud03.addcredit();
}
else
{
System.out.println("Identifiant non valide, crédit non ajouté");
}
}
// 2) Vérifier la préséance d'un nom
else if ( choix == 2)
{
System.out.println("Entrez l'identifiant de l'étudiant 1: ");
int id1 = scan.nextInt();
System.out.println("Entrez l'identifiant de l'étudiant 2: ");
int id2 = scan.nextInt();
if (id1==1 || id2==2)
{
comp01 = etud01.compareTo(etud02);
System.out.println(comp01);
}
else if (id1==1 || id2==3)
{
comp01 = etud01.compareTo(etud03);
System.out.println(comp01);
}
else if (id1==2 || id2==1)
{
comp01 = etud02.compareTo(etud01);
System.out.println(comp01);
}
else if (id1==2 || id2==3)
{
comp01 = etud02.compareTo(etud03);
System.out.println(comp01);
}
else if (id1==3 || id2==1)
{
comp01 = etud03.compareTo(etud01);
System.out.println(comp01);
}
else if (id1==3 || id2==2)
{
comp01 = etud03.compareTo(etud02);
System.out.println(comp01);
}
else
System.out.println("Le nom 1 vient à égalité");
}
//3) Comparer 2 noms
else if ( choix == 3)
{
System.out.println("Entrez l'identifiant de l'étudiant 1: ");
int id1 = scan.nextInt();
System.out.println("Entrez l'identifiant de l'étudiant 2: ");
int id2 = scan.nextInt();
if (id1==1 || id2==2)
{
rep01 = etud01.nom.equals(etud02.nom);
System.out.println(rep01);
}
else if (id1==1 || id2==3)
{
rep02 = etud01.nom.equals(etud03.nom);
System.out.println(rep02);
}
else if (id1==2 || id2==1)
{
rep03 = etud02.nom.equals(etud01.nom);
System.out.println(rep03);
}
else if (id1==2 || id2==3)
{
rep04 = etud02.nom.equals(etud03.nom);
System.out.println(rep04);
}
else if (id1==3 || id2==1)
{
rep05 = etud03.nom.equals(etud01.nom);
System.out.println(rep05);
}
else if (id1==3 || id2==2)
{
rep06 = etud03.nom.equals(etud02.nom);
System.out.println(rep06);
}
else
System.out.println("Le nom 1 vient à égalité");
}
// 4) Voir la moyenne cumulative
else if ( choix == 4)
{
System.out.println("Entrez l'identifiant de l'étudiant: ");
int id1 = scan.nextInt();
if (id1==1)
{
moy = etud01.getmoyenneCumul();
System.out.println("Moyenne: " + moy );
}
else if (id1==2)
{
moy = etud02.getmoyenneCumul();
System.out.println("Moyenne: " + moy );
}
else
{
moy = etud03.getmoyenneCumul();
System.out.println("Moyenne: " + moy );
}
}
else
{
}
}
while(choix != 5);
}
} |
Partager