Dr MEHRI TURKI IMEN - Traitement du double menton : Une nouvelle technique tu...
Pooderniercours
1. • public class Point {
• private int abs,ord;
• public int getAbs() {
• return abs;
• }
• public void setAbs(int a) {
• abs = a;
• }
• public int getOrd() {
• return ord;
• }
2. • public void setOrd(int o) {
• ord = o;
• }
• Point(int a,int b)
• {abs=a;
• ord=b;}
• public String toString() {
• return " [abs=" + abs + ", ord=" + ord + "]";
• }
• }
3. • public class Courbe {
• private int nbrPoint , nbrMaxPoint;
• private Point tab[];
• //les getteurs et les setteurs
• public int getNbrPoint() {
• return nbrPoint;
• }
• public void setNbrPoint(int n1) {
• nbrPoint = n1;
• }
• public int getNbrMaxPoint() {
• return nbrMaxPoint;
• }
• public void setNbrMaxPoint(int n2) {
• nbrMaxPoint = n2;
• }
• public Point[] getTab() {
• return tab;
• }
• public void setTab(Point[] t) {
• tab = t;}
4. • //le constructeur
• public Courbe(int n ){
• nbrPoint=0;
• nbrMaxPoint=n;
• tab=new Point [n];}
• //methodes possibles
• public Point minCourbe (){
• int j=0;
• int minOrd=tab[0].getOrd();
• for (int i=1;i<nbrPoint;i++)
• { if (tab[i].getOrd() < minOrd) j=i;}
• return tab[j];
• }
• public void affiche () {
• System.out.print("voici la courbe");
• for (int i=0;i<nbrPoint;i++)System.out.print(tab[i]+" ");}
5. • public int chercher (Point p){
• int j=-1;
• for (int i=0;i<nbrPoint;i++)
• {if( (tab[i].getOrd()==p.getOrd()) &&(tab[i].getAbs()==p.getAbs()))
• j=i;}
• return j; }
• public void ajouter (Point p){
• if ( (nbrMaxPoint>nbrPoint) && (chercher(p)==-1) )
• { tab[nbrPoint]=p;nbrPoint ++;}
• else System.out.println("tableau plein");}
• public void supprimer (Point p) {
• int j = chercher(p);
• if(j==-1) System.out.println("le point"+p+" n'existe meme pas dans cette
courbe !");
• else {
• for (int i=j;i<nbrPoint;i++) {
• tab[i]=tab[i+1];}
• nbrPoint--;}}
• }
6. • public class TestCourbe {
• public static void main(String[] args) {
• Courbe c1 = new Courbe(100);
• Point p1=new Point(5,6);
• Point p2=new Point(6,7);
• Point p3=new Point(11,55);
• Point p4=new Point(17,41);
• c1.ajouter(p1);
• c1.ajouter(p2);
• c1.ajouter(p3);
• c1.affiche();