الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

مساعدة Sort لبيانات

بدأه ishere11 في 9 أكتوبر 2010 · 3 رد · 340 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبراكاته

أريد شرح هدا الكود

public class Joueur Implements Comparable {

int reg;
int departement;
int point;
String nom;
.......

   Public Int CompareTo(Joueur autreJoueur)
   {
      int resultat;
      if (this.point > autrejoueur.point)
         resultat = 1;
      if (this.point < autrejoueur.point)
         resultat = -1;
      if (this.point == autrejoueur.point)
         resultat = 0;
      return resultat;
   }
}

أريد فقط الفرق بين this.point و autrejoueur.point

public class execl{

ArrayList LesJoueurs = new ArrayList();
........
LesJoueurs.Add();
LesJoueurs.Add();
LesJoueurs.Add();
LesJoueurs.Add();
........
LesJoueurs.Sort();
}

جزاكم الله كل الخير

#2

الكود مليئ بالأخطاء.

الجافا تفرق بين ال majuscule و ال minuscule

public int compareTo(Joueur autreJoueur)

وليس

Public Int CompareTo(Joueur autreJoueur)

ال argument الذي تمرره هو autreJoueur، وداخل compareTo تستعمل autrejoueur. غيره إلى autreJoueur

add وليس Add

الطريقة add تستعمل إضافة كائن ما، لكنك لا تضيف أي شيئ

لا توجد أي طريقة sort في الفئة ArrayList. هي موجودة في الفئة java.util.Collections

-------------------------------------

ما هو استفسارك بالضبط؟

#3
ishere11 كتب:

السلام عليكم ورحمة الله وبراكاته

أريد شرح هدا الكود

public class Joueur Implements Comparable {

int reg;
int departement;
int point;
String nom;
.......

   Public Int CompareTo(Joueur autreJoueur)
   {
      int resultat;
      if (this.point > autrejoueur.point)
         resultat = 1;
      if (this.point < autrejoueur.point)
         resultat = -1;
      if (this.point == autrejoueur.point)
         resultat = 0;
      return resultat;
   }
}

أريد فقط الفرق بين this.point و autrejoueur.point

public class execl{

ArrayList LesJoueurs = new ArrayList();
........
LesJoueurs.Add();
LesJoueurs.Add();
LesJoueurs.Add();
LesJoueurs.Add();
........
LesJoueurs.Sort();
}

جزاكم الله كل الخير

شكرا على الملا حظة أريد ِشرح كيف عمل sort لبيانات

public class Joueur Implements Comparable {

int reg;
int departement;
int point;
String nom;
.......

   Public Int compareTo(Joueur autreJoueur)

 {
أريد الشرح هدا الكود
      int resultat;

      if (this.point > autrejoueur.point)
         resultat = 1;
      if (this.point < autrejoueur.point)
         resultat = -1;
      if (this.point == autrejoueur.point)
         resultat = 0;
      return resultat;
   }
}

public class execl{

ArrayList LesJoueurs = new ArrayList();
........
LesJoueurs.add(new Joueur(10,168657,18,Ahmed));
LesJoueurs.add(new Joueur(15,4557,12,Amal));
LesJoueurs.add(new Joueur(11,1686,17,soufiane));

 Collections.sort(LesJoueurs);
}
#4

اقتباس
The compareTo method compares the receiving object with the specified object and returns a negative integer, 0, or a positive integer depending on whether the receiving object is less than, equal to, or greater than the specified object.

http://download.oracle.com/javase/tutorial/collections/interfaces/order.html

مواضيع مشابهة