Aide en java
Fermé
lafa73
Messages postés
39
Date d'inscription
vendredi 7 mars 2008
Statut
Membre
Dernière intervention
27 octobre 2008
-
8 avril 2008 à 15:15
Utilisateur anonyme - 9 avril 2008 à 11:14
Utilisateur anonyme - 9 avril 2008 à 11:14
A voir également:
- Aide en java
- Scanf en java ✓ - Forum Java
- Jeux java itel ✓ - Forum Jeux vidéo
- Java runtime - Télécharger - Langages
- Java apk - Télécharger - Langages
- Java heap space ✓ - Forum Java
2 réponses
Voilà une réponse possible :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;
public class Etudiant {
private Vector matieres;
private Vector coeff;
private Vector notes;
public Vector getMatieres(){return matieres;}
public Vector getCoeff(){return coeff;}
public Vector getNotes(){return notes;}
public Etudiant(){
matieres = new Vector();
coeff = new Vector();
notes = new Vector();
}
public void addMatiere(String nomMatiere){
matieres.add(nomMatiere);
}
public void addCoeff(Double coef){
coeff.add(coef);
}
public void addNote(Double note){
notes.add(note);
}
public void saisir(){
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
String ligne;
int choix = 0;
do{
try{
System.out.println("Choisissez parmi les actions suivantes :");
System.out.println("1 - Ajouter un résultat");
System.out.println("2 - Quitter");
ligne = br.readLine();
choix = Integer.parseInt(ligne);
if(choix == 2)
break;
System.out.println("Donnez la matière : ");
ligne = br.readLine();
addMatiere(ligne);
System.out.println("Donnez le coefficient pour la matière "+ligne+" : ");
ligne = br.readLine();
addCoeff(new Double(ligne));
System.out.println("Donnez la note de coefficient "+ligne+" : ");
ligne = br.readLine();
addNote(new Double(ligne));
}
catch(IOException ioe){
ioe.printStackTrace();
}
}
while(true);
}
public String toString(){
StringBuffer retour = new StringBuffer();
retour.append("Matière \tCoefficient \tNote \n");
for(int i=0;i<matieres.size();i++){
retour.append(matieres.elementAt(i));
retour.append(" \t");
retour.append(coeff.elementAt(i));
retour.append(" \t");
retour.append(notes.elementAt(i));
retour.append("\n");
}
return retour.toString();
}
public static void main(String[] args){
Etudiant etudiant = new Etudiant();
etudiant.saisir();
System.out.print(etudiant.toString());
}
}
8 avril 2008 à 17:59