0% found this document useful (0 votes)
13 views5 pages

Nouveau Document Texte

This document defines a Java class called "etudient" that represents a student. The etudient class stores student attributes like name, grades, and calculates grade average. Methods are defined to create etudient objects, input student data, display student data, sort students by average grade, and output a ranked list of students. The main method demonstrates creating etudient objects, calling methods to manage and display student data.

Uploaded by

imen gueddess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views5 pages

Nouveau Document Texte

This document defines a Java class called "etudient" that represents a student. The etudient class stores student attributes like name, grades, and calculates grade average. Methods are defined to create etudient objects, input student data, display student data, sort students by average grade, and output a ranked list of students. The main method demonstrates creating etudient objects, calling methods to manage and display student data.

Uploaded by

imen gueddess
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

package part1;

import java.util.ArrayList;
import java.util.Scanner;

public class etudient {


private String prenom;
private String nom;
public double moyenne;
private int rang;
private ArrayList<Double> notes=new ArrayList<Double>();

public String getprenom() {


return prenom;
}

public void setprenom(String prenom) {


this.prenom = prenom;
}

public String getnom() {


return nom;
}

public void setnom(String nom) {


this.nom = nom;
}

public ArrayList<Double> getNotes() {


return notes;
}

public void setNotes(ArrayList<Double> notes) {


this.notes = notes;
}

public void creerobjetetudiant (){


int x; double a;
String nom,prenom;
ArrayList<Double> notes = new ArrayList<Double>();
Scanner scanner;
scanner=new Scanner(System.in);
System.out.println("prenom :");
prenom =scanner.next() ;
this.prenom=prenom;

System.out.println("nom :");
nom =scanner.next() ;

this.setnom(nom);
System.out.println("nombre de notes :");
x =scanner.nextInt() ;
for(int i=0; i<x; i++){
System.out.print("note numero"+(i+1)+": ");
a =scanner.nextDouble() ;
notes.add(a);
}
this.setNotes(notes);
}

public static void affichenote(ArrayList<Double> nt){


for(int i=0;i<nt.size();i++){
System.out.print("note n: "+i+" est "+nt.get(i));

}
System.out.println(" ");
}

public static double moyenne(ArrayList<Double> nt){


double s=0;
for(int i=0;i<nt.size();i++){
s+=nt.get(i);
}
return s/nt.size();

public String showetud(){

return("etudiant :"+this.prenom+" "+this.nom+" moyenne :


"+etudient.moyenne(this.notes));

public boolean comparename(etudient s){


return((this.prenom.equalsIgnoreCase(s.prenom)) &&
(this.nom.equalsIgnoreCase(s.nom)));
}
public static boolean verif(etudient [] clas ,etudient k, int n)

{
int j=0;
while (true){
if (j==n){
break;
}
if (k.comparename(clas[j])==true) {
return false;

}
j++;

}
return true;
}

public void tabetud(etudient [] clas ,int n){


clas[0] =new etudient();
clas[0].creerobjetetudiant ();
for (int i=1;i<clas.length;i++){
clas[i] =new etudient();
while (true){

clas[i].creerobjetetudiant ();

if (verif(clas,clas[i],i)==true){
break;
}
}
}

}
public void affichtab(etudient[] clas , int n){
for (int i=0;i < n;i++){
System.out.println(clas[i].showetud());
}
}

public void tri(etudient[] clas,int n){


for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (clas[j].moyenne > clas[j + 1].moyenne) {
etudient temp = clas[j];
clas[j] = clas[j + 1];
clas[j + 1] = temp;
}
}
}

public void affichtab_avec_range(etudient[] clas , int n){


for (int i=0;i<n;i++){
clas[i].rang=i+1;
System.out.println("rang :"+clas[i].rang);
System.out.println(clas[i].showetud());
}
}

/*

public static void main(String []args){


etudient[] clas = new etudient[2] ;
etudient etud1= new etudient ();
creerobjetetudiant(etud1);
System.out.println(showetud(etud1));
etudient etud2= new etudient ();
creerobjetetudiant(etud2);
System.out.println(showetud(etud2));
System.out.print("etudient 1 et 2 sont-ils identiquent :
"+etud1.comparename(etud2));
if (etud1.comparename(etud2)==false)
{
if( etud1.moyenne > etud2.moyenne){
System.out.println("le meilleur "+showetud(etud1));
}
else{
System.out.println("le meilleur "+showetud(etud2));
}
}
tabetud(clas,2);
affichtab(clas,2);
tri(clas,2);
System.out.println("tableau triee : ");
affichtab_avec_range(clas,2);

}*/
}

---------------------------------------------------------------------------------
package part1;

import java.util.Scanner;

public class test {


public static void main(String []args){
Scanner scanner;
scanner=new Scanner(System.in);
System.out.println("nombre des etudients :");

int n=scanner.nextInt() ;
etudient[] clas = new etudient[2] ;
etudient etud1= new etudient ();
/*etud1.creerobjetetudiant();
System.out.println(etud1.showetud());
etudient etud2= new etudient ();
etud2.creerobjetetudiant();
System.out.println(etud2.showetud());
System.out.println("etudient 1 et 2 sont-ils identiquent :
"+etud1.comparename(etud2));
if (etud1.comparename(etud2)==false)
{
if( etud1.moyenne >= etud2.moyenne){
System.out.println("le meilleur "+etud1.showetud());
}
else{
System.out.println("le meilleur "+etud2.showetud());
}
}*/
etud1.tabetud(clas,n);
etud1.affichtab(clas,n);
etud1.tri(clas,n);
System.out.println("tableau triee : ");
etud1.affichtab_avec_range(clas,n);

}
}

You might also like