i want to output final coccer team standing that uses random so every time the match is played the final four team changes so how do i output that the ouput to the file changes as well

this is the final four

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("" );
										}




							 	 }

this is the bubble sort and what is needed is to print out from first place to fourth place and remmember every time the match is run the team changes. i am also putting an output file i have but it is not creating the text file.

try{
      //Open the file for both reading and writing
      RandomAccessFile rand = new RandomAccessFile("tournamentresults.txt","r");
      int i=(int)rand.length();
      System.out.println("Length: " + i);
         rand.seek(0);  //Seek to start point of file
      for(int team = 0; team < i; team++){
        byte b = rand.readByte(); //read byte from the file
        System.out.print((char)b); //convert byte into char
      }
      rand.close();
    }
      catch(IOException e)
    {
    System.out.println(e.getMessage());
    }






  }// end of method







}






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 t :array)
	  	{
	  		System.out.print(t + " ");
	  }//end for loop

	  for(Team t :array)
	  	  	{
	  	  		System.out.print(t + " ");
	  }//end for loop




}//end method printArray

You are thinking of a random access RW file, presumably for in-place updating, but for the size you have here it would be much easier to just read the whole file into a suitable collection/class structure at startup, and write the whole thing back out (overwriting the file) at shutdown.
There's no reason why you shouldn't be able to read or write the whole shebang as a single Collection object in a single statement.

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