Pooderniercours

786 views

Published on

Published in: Health & Medicine, Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
786
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
62
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Pooderniercours

  1. 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. 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. 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. 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. 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+" nexiste meme pas dans cette courbe !");• else {• for (int i=j;i<nbrPoint;i++) {• tab[i]=tab[i+1];}• nbrPoint--;}}• }
  6. 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();
  7. 7. • Point minimum= c1.minCourbe();• System.out.println(minimum);• c1.supprimer(p2);• c1.supprimer(p4);• }• }

×