I need help with this, im writing a league system and i need to order the teams by the points they have received max to min, im lost to where to begin any help would be good.

public class League
{
   /* instance variables */
   private Team name;
   private int points;

   /**
    * Constructor for objects of class League.
    */
   public League(Team aname)
   {
      super();
      name = aName;
      points = 0;
   }

   /**
    * Returns the receiver's name Team
    */
   public Dancer getName()
   {
      return this.name;
   }
    
      
   /**
    * Returns the receiver's points
    */
   public int getPoints()
   {
      return points;
   }
     
   /**
    * Sets the receiver's points
    */
   public void setPoints(int aPoints)
   {
      this.points = aPoints;
   }

method for order points

public void orderPoints()
    {


    }

I'm guessing i need to use
String maxScore = Collections.min(points);
String maxScore = Collections.ax(points); but i might be in the wrong place

Yes, those methods could work provided the contents of points follows the rules. Read the API doc for the methods for what the rules are.

You can sort by whatever comparison you like if you pass it a Comparator or implement the Comparable interface. Your Team class currently doesn't have any natural ordering. Java has no idea how you would want to sort a collection of such things. It does know the natural ordering for things like numbers and strings, but you have created this data type yourself, so you need to specify how it is to be compared with other instances of this type.

Take a quick read through the tutorial on Object Ordering and perhaps it will help.

i was going down this route but doesnt seem to work

Collections.sort(points, Collections.reverse());


I;m about to read the other tutorial now

Your class is somewhat incomplete right now. A League is a collection of Teams. You will want to sort a List of Team objects by their point value, which is just an int. You current class structure does not reflect this.

This article has been dead for over six months. Start a new discussion instead.