i need to call an array called team into a bubble sort that swaaps 3rd 4th ist and 2nd place in order. in the code i will list the code for the out come of the match which is good no errors there but i need to get the bubble sort to swap and print out the results. i keep getting these errors.

public void printArray (Team[] array)this is done in TextPad and this error appears four time
1. illegal start of expression and it points to the p in public.
2. illegal start of expression and points to the v in void.
3. it point to the bracket before team and says ';' expected.
4. it points to the bracket after array and says ';' expected

public void runFinalRound()
{

        int count = 1;
        current = head;
        int c = 0;
        System.out.println("\n                   WELCOME BACK SPECTATORS & FANS \n                 THE FINAL ROUND IS ABOUT TO BEGIN");

             System.out.println("\nTHIRD AND FOURTH PLACE " + count);
             System.out.println("" + current.newTeam.teamName + "V.S  " +current.link.newTeam.teamName + " " +(count + ran.nextInt(5))+":05pm @ HASLEY CROFORD STADIUM ");


             current.newTeam.goalsFor = ran.nextInt(2);
             current.link.newTeam.goalsFor = ran.nextInt(2);
             System.out.println("\nScore " + current.newTeam.goalsFor +":"+current.link.newTeam.goalsFor);


                 if(current.newTeam.goalsFor > current.link.newTeam.goalsFor)
                 {
                     current.newTeam.points = 10;
                      current.link.newTeam.points = 8;

                     System.out.println("3rd :" + current.newTeam.teamName);
                      System.out.println("4th :" + current.link.newTeam.teamName);
                     System.out.println("" );
                 }
                 else
                 if(current.newTeam.goalsFor < current.link.newTeam.goalsFor)
                  {
                       current.newTeam.points = 8;
                       current.link.newTeam.points = 10;
                       System.out.println("3rd :" + current.link.newTeam.teamName);
                      System.out.println("4th :" + current.newTeam.teamName);

                  }

                  else
                  while(current.newTeam.goalsFor == current.link.newTeam.goalsFor)
                    {
                     System.out.println("Match Drawn So This is Extra Time     ");
                      current.newTeam.goalsFor = ran.nextInt(2);
                      current.link.newTeam.goalsFor = ran.nextInt(2);
                       System.out.println("Score " + current.newTeam.goalsFor +":"+current.link.newTeam.goalsFor);

                       if(current.newTeam.goalsFor > current.link.newTeam.goalsFor)
                         {
                           current.newTeam.points = 10;
                           current.link.newTeam.points = 8;

                           System.out.println("3rd :" + current.newTeam.teamName);
                           System.out.println("4th :" + current.link.newTeam.teamName);
                           System.out.println("" );
                          }
                        else
                          if(current.newTeam.goalsFor < current.link.newTeam.goalsFor)
                           {
                             current.newTeam.points = 8;
                             current.link.newTeam.points = 10;
                             System.out.println("3rd :" + current.link.newTeam.teamName);
                             System.out.println("4th :" + current.newTeam.teamName);

                           }
                           else
                            if(current.newTeam.goalsFor == current.link.newTeam.goalsFor)
                           {
                             System.out.println("\nMATCH STILL DRAWN SO ITS DOWN TO PENALTY SHOOT OUT   ");

                             current.newTeam.goalsFor = ran.nextInt(5);
                              current.link.newTeam.goalsFor = ran.nextInt(5);
                               System.out.println("Score " + current.newTeam.goalsFor +":"+current.link.newTeam.goalsFor);


                               if(current.newTeam.goalsFor > current.link.newTeam.goalsFor)
                               {
                                 current.newTeam.points = 10;
                                 current.link.newTeam.points = 8;

                                 System.out.println("3rd :" + current.newTeam.teamName);
                                 System.out.println("4th :" + current.link.newTeam.teamName);
                                 System.out.println("" );
                                }
                                else
                                 if(current.newTeam.goalsFor < current.link.newTeam.goalsFor)
                                 {
                                   current.newTeam.points = 8;
                                   current.link.newTeam.points = 10;
                                   System.out.println("3rd :" + current.link.newTeam.teamName);
                                   System.out.println("4th :" + current.newTeam.teamName);

                             }

                           }

                 System.out.println("\nFINAL " + count);
                 System.out.println("" + current.link.link.newTeam.teamName + " V.S  " +current.link.link.link.newTeam.teamName + " " +(count + ran.nextInt(5))+":05pm @ HASLEY CROFORD STADIUM ");


                        current.link.link.newTeam.goalsFor = ran.nextInt(2);
                        current.link.link.link.newTeam.goalsFor = ran.nextInt(2);
                        System.out.println("\nScore " + current.link.link.newTeam.goalsFor +":"+current.link.link.link.newTeam.goalsFor);


                         if(current.link.link.newTeam.goalsFor > current.link.link.link.newTeam.goalsFor)
                         {
                           current.link.link.newTeam.points = 20;
                           current.link.link.link.newTeam.points = 15;

                           System.out.println("1st :" + current.link.link.newTeam.teamName);
                           System.out.println("2nd :" + current.link.link.link.newTeam.teamName);
                           System.out.println("" );
                        }
                        else
                            if(current.link.link.newTeam.goalsFor < current.link.link.link.newTeam.goalsFor)
                            {
                               current.link.link.newTeam.points = 15;
                               current.link.link.link.newTeam.points = 20;
                               System.out.println("1st :" + current.link.link.link.newTeam.teamName);
                               System.out.println("2nd :" + current.link.link.newTeam.teamName);

                            }

                            else
                             while(current.link.link.newTeam.goalsFor == current.link.link.link.newTeam.goalsFor)
                            {
                               System.out.println("Match Drawn So This is Extra Time     ");
                               current.link.link.newTeam.goalsFor = ran.nextInt(2);
                               current.link.link.link.newTeam.goalsFor = ran.nextInt(2);
                               System.out.println("Score " + current.link.link.newTeam.goalsFor +":"+current.link.link.link.newTeam.goalsFor);

                                if(current.link.link.newTeam.goalsFor > current.link.link.link.newTeam.goalsFor)
                                {
                                    current.link.link.newTeam.points = 20;
                                    current.link.link.link.newTeam.points = 15;

                                    System.out.println("1st :" + current.link.link.newTeam.teamName);
                                    System.out.println("2nd :" + current.link.link.link.newTeam.teamName);
                                    System.out.println("" );
                                }
                                else
                                  if(current.link.link.newTeam.goalsFor < current.link.link.link.newTeam.goalsFor)
                                  {
                                     current.link.link.newTeam.points = 15;
                                     current.link.link.link.newTeam.points = 20;
                                     System.out.println("1st :" + current.link.link.link.newTeam.teamName);
                                     System.out.println("2nd :" + current.link.link.newTeam.teamName);

                                  }
                                  else
                                    if(current.link.link.newTeam.goalsFor == current.link.link.link.newTeam.goalsFor)
                                    {
                                       System.out.println("\nMATCH STILL DRAWN SO ITS DOWN TO PENALTY SHOOT OUT   ");

                                       current.link.link.newTeam.goalsFor = ran.nextInt(5);
                                       current.link.link.link.newTeam.goalsFor = ran.nextInt(5);
                                       System.out.println("Score " + current.link.link.newTeam.goalsFor +":"+current.link.link.link.newTeam.goalsFor);
                                    }

                                        if(current.link.link.newTeam.goalsFor > current.link.link.link.newTeam.goalsFor)
                                        {
                                            current.link.link.newTeam.points = 20;
                                            current.link.link.link.newTeam.points = 15;

                                            System.out.println("1st :" + current.link.link.newTeam.teamName);
                                            System.out.println("2nd :" + current.link.link.link.newTeam.teamName);
                                            System.out.println("" );
                                        }



public void bubbleSort(Team array[])
    {

        int arrayLength = array.length;//get array length

         for(int i = 0; i < arrayLength; i++)
        {
        for(int c = 1; c < (arrayLength - i); c++)
        {
            //compare and swap
        if(array[c - 1].points > array[c].points)
        {
            Team temp = array[c];
            array[c] = array[c - 1];
            array[c - 1] = temp;



        }//end if



    }//end inner for loop



  }//end outer for loop

  public void printArray(Team[] array)
  {

      System.out.print("\n Array Data: ");

                                    for(Team i = 0; i < array.length; i++)
                                    {
                                        System.out.print(array[i] + " ");
                                    }//end for loop




}//end method printArray



}//



                                 }

Edited 3 Years Ago by mike_2000_17: Fixed formatting

ok this is how i have it and it has the same errors

public void bubbleSort(Team array[])
	{

		int arrayLength = array.length;//get array length

		 for(int i = 0; i < arrayLength; i++)
		{
		for(int c = 1; c < (arrayLength - i); c++)
		{
			//compare and swap
		if(array[c - 1].points > array[c].points)
		{
			Team temp = array[c];
			array[c] = array[c - 1];
			array[c - 1] = temp;



		}//end if



	}//end inner for loop



  }//end outer for loop

  public void printArray(Team[] array)
  {

	  System.out.print("\n Array Data: ");

	  	for(Team i = 0; i < array.length; i++)
	  	{
	  		System.out.print(array[i] + " ");
	  }//end for loop




}//end method printArray



}//

I'm also using a bubblesort on an array and it seems to work. In terms of your variables, this is what it looks like:

public void bubbleSort(Team array[])
	{

		int arrayLength = array.length;//get array length

		 for(int i = 0; i < arrayLength - 1; i++)//changed from i < arrayLength
		{
		for(int c = 0; c < (arrayLength - i); c++)//start c at 0 instead of 1
		{
			//compare and swap
		if(array[c].points > array[c+1].points)//changed from if(array[c - 1].points > array[c].points)
		{
			Team temp = array[c];
			array[c] = array[c+1];//changed from array[c] = array[c-1]
			array[c + 1] = temp;//changed from array[c - 1] = temp;



		}//end if



	}//end inner for loop



  }//end outer for loop
}//close bubblesort method - you still don't have this closing curly brace

I haven't tried implementing this code yet in the context of your whole project (I'm too lazy to change your code in terms of mine, lol) so it could be wrong.

the errors still remain four but they are now different.
in the printArray method
1. incompatible types found: int
required Match.Team
for(Team i = 0; i < array.length; i++)
2. operator < cannot be applied to Match.Team, int
for(Team i= 0; < array.length; i++)
3. operator ++ cannot be applied to Match.Team
for(Team i = 0; i < array.length; i++)
4. incompatible types found: Match.Team
required: int
System.out.print(array + ""); i is the one pointed out

public void bubbleSort(Team array[])
	{

		int arrayLength = array.length;//get array length

		 for(int i = 0; i < arrayLength; i++)
		{
		for(int c = 0; c < (arrayLength - i); c++)
		{
			//compare and swap
		if(array[c].points > array[c + 1].points)
		{
			Team temp = array[c];
			array[c] = array[c + 1];
			array[c + 1] = temp;



		}//end if



	}//end inner for loop



  }//end outer for loop

}//end bubbleSort

  public void printArray(Team[] array)
  {

	  System.out.print("\n Array Data: ");

	  	for(Team i = 0; i < array.length; i++)
	  	{
	  		System.out.print(array[i] + " ");
	  }//end for loop




}//end method printArray

i got to get it to print out to see if it works and place them by points from 1st to 4th.

A team is a Team, and an int is an int.
You are trying to assign the value 0 to an instance of Team, ditto compare it to an int, and add 1 to it. You should be using an int to index your array in yourt loop.

ps

The "extended for loop" or "for each loop" is a cleaner way to code this:

for (Team t : array) { // spoken as "for each Team t in array"
  System.out.print(t + " ");
}
This article has been dead for over six months. Start a new discussion instead.