pooderniercours

7

Click here to load reader

Upload: amel-morchdi

Post on 20-Jun-2015

579 views

Category:

Health & Medicine


0 download

TRANSCRIPT

Page 1: Pooderniercours

• public class Point {

• private int abs,ord;

• public int getAbs() {

• return abs;

• }

• public void setAbs(int a) {

• abs = a;

• }

• public int getOrd() {

• return ord;

• }

Page 2: Pooderniercours

• public void setOrd(int o) {

• ord = o;

• }

• Point(int a,int b)

• {abs=a;

• ord=b;}

• public String toString() {

• return " [abs=" + abs + ", ord=" + ord + "]";

• }

• }

Page 3: Pooderniercours

• 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;}

Page 4: Pooderniercours

• //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]+" ");}

Page 5: Pooderniercours

• 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--;}} • }

Page 6: Pooderniercours

• 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();

Page 7: Pooderniercours

• Point minimum= c1.minCourbe();

• System.out.println(minimum);

• c1.supprimer(p2);

• c1.supprimer(p4);

• }

• }