i have to create a soccer tournament like the world cup that starts off with 32 teams that goes down to 16 then quaters, semis and final i have to use sort stacks or queues or even linkedlist. there must also be arrays, classes. gui for bonus marks but i want to get the program before tackling gui. so i created a file with the 32 teams but i kind of don't know where to go from there so this is what i have.

import java.io.*;
import java.lang.*;
import java.util.*;

public class Tournament {
	
	private Formatter File;
	
	public void openFile(){
		try{
			File = new Formatter("tournament.txt");
		}
		catch(Exception e){
			System.out.println("You have an error");
		}
	}
	
	public void addRecords(){
		File.format("%s			%s		%s			%s			%s			%s		%s		%s",
				"Group A","Group B", "Group C", "Group D", "Group E", "Group F", "Group G", "Group H");
		File.format("\n%s			%s	%s			%s		%s		%s	%s			%s", 
				"Algeria", "Argentina", "Denmark", "Honduras", "Netherlands", "Slovakia", "USA", "Japan");
		File.format("\n%s		%s		%s			%s		%s		%s		%s		%s", 
				"Australia", "England", "Italy", "New Zealand", "Slovenia", "Brazil", "France", "Nigeria");
		File.format("\n%s	%s	%s			%s		%s		%s		%s		%s", 
				"South Africa", "Cameroon", "Germany", "Korea DPR", "Paraguay", "Spain", "Chile", "Ghana");
		File.format("\n%s		%s	%s		%s			%s			%s		%s		%s", 
				"Korea Rep", "Portugal", "Switzerland", "Greece", "Mexico", "Serbia", "Uraguay", "Trinidad and Tobago");
	}
	
	public void closeFile(){
		File.close();
	}

}

the above code is for the file

this code is the main and what ever is suppose to come here but i am not sure so i tried starting with reading the file but don't know if that is the write start and getting some errors there as well.

import java.io.*;
import java.util.*;

public class Football {
	
	public static void main(String[] args){
		
		boolean  enter;
		int counter = 0;
		char reply;
		String Teams;
		int goals;
		int points;
		
		Tournament x = new Tournament();
		x.openFile();
		x.addRecords();
		x.closeFile();
		
		private Scanner File;
		
		public void openFile(){
			try{
				File = new Scanner(new File("tournament.txt"));
			}
			
			catch(Exception e){
				System.out.println("could not find file");
			}
		}
		
		public void readFile(){
			while(File.hasNext()){
				String a = File.next();
			}
		}
	}

}

First off there is a class called File, so rename your Formatter and Scanner objects something else. It's too confusing.

Second, make life easy for yourself and create a text file with a text editor and have Jave READ the file (as opposed to writing it), so dump the first code where you are writing to a file.

Third, I'm seeing a distinct lack of class data members in these classes. You need to figure out what data Teams and Tournaments need to store. No point reading data from a file if you've got nothing to put the data into.

ok the code for writing to text file is gone and since i am using eclipse i just used a text file in eclipse. now the data for the teams would be the goals and the points.there are 8 groups from a to h and the teams in each group have to play each other and two teams has to move forward but i honestly don't have a clue of how to start since i can't read the file yet

>> but i honestly don't have a clue of how to start since i can't read the file yet

OK, then ignore all the other aspects of the assignment for now and learn how to read data from a file for now. Then come back. Just learn to read the data and spit it back out first. Then come back to your actual project. Lots of good examples out there. Here's one, but there are many, many others.

http://www.kodejava.org/examples/241.html

ok i forgot about the project and worked on reading a file but i want to know since i have the file in tabular form is there a way to get it back in tabular because some out of position while others are in position so is there a way for all of it to be just how i typed it.

By "tabular form", you mean that the file is separated by tabs? It might be useful to see the file. I'm not 100% sure what's in it and how everything is supposed to end up in memory on the Java end of things.

You have input (that's the file), you have memory (that's the data stored in your Java classes), and you have output (either printing to the screen or writing to a file). You have read methods and write methods. You might possibly have a toString() method, which turns what's in memory into a String. toString() could be considered, roughly, and output/write method or at least a helper function to an output/write method.

If you want tab-delineated output, you would output a tab between all class data members. I think that's a totally separate issue from how to READ the file though. You read the data into memory and you write the memory to wherever you're writing it to. Two completely independent functions.

I can't suggest a fix because I would need to see the code, the input file, the desired output file, and the actual output file in order to understand what's out of position.

I once had to do a program like this for a test, but in C, with 16 teams.
The logic I used was like this, I made a class (actually in C, it's struct, but I'll say everything as if it was Java) named Team and that class had a String with the name, an Array of Integers containing all the games they could play, and Boolean that told if they were still participating (I initialized then all with true, because all teams begin playing)..
I had to scan every result of every game and then tell who was the winner, so I scanned the result for a game, and then looked for the Teams that could play that game (Looking in the array of Integers for the specified game number) and that were still playing (Checking if the boolean was still true), then I saw who won and changed the Boolean value of the looser to false.
I hope I helped, if I wasn't clear please let me know! :)

i would have to use a queue and a sorting algorithm so that whats confusing me about how to start.

ok i attempted something but i did it without using a queue but i need to be able to use it i did it from some c++ knowledge but with the errors i can't test to see if it works so it needs help. i have class, arrays and a bubble sort. from what is required it is missing the queue and at the end i am suppose to be able to print out the results and the teams info.

import java.io.*;
import java.util.*;

public class Football {
	
	public static void main(String[] args){
		
		boolean  enter;
		int counter = 0;
		char reply;
		String Teams[];
		int goals[];
		int points[];
		int temp;
		String temps;
		
		
		
		System.out.println("Please choose one of the following options");
		System.out.println("Option 1:Start Tournament");
		System.out.println("Option 2:End Program");
		
		
		if(enter == 1){
			
			System.out.println("round one starts");
			
			for(int i = 0; i <= 7; i++){
				System.out.println("Segment: x+1");
				
				for(int j = 0; j <=2; j++){
					goals[counter] = 5 + rand()% (10-5 +1);
					System.out.println(goals[counter]);
					
				}
			}
		}
		
		for(int i = 0; (i <= 31); i++)
	     {

	          for (int j=0; j < 31; j++)
	         {
	               if (goals[j+1] > goals[j] & Teams[j+1] > Teams[j])      // ascending order simply changes to <
	              {
	                     temps =  Teams[j];             // swap elements
	                     Teams[j] =  Teams[j+1];
	                     Teams[j+1] = temps;

	                    temp = goals[j];             // swap elements
	                    goals[j] = goals[j+1];
	                    goals[j+1] = temp;
	                                // indicates that a swap occurred.

	               }
	          }
	     }

These arrays all need to be initialized before you can use them. Example...

goals = new int[20];

when i put new i recieve an error with new stating invalid expression.

Then you're putting it in the wrong place or you did something else wrong. We have no idea what you did. You have to post the up-to-date code, the error message, and the line number every time you post.

remember this still ha ve to be in a queue which i am still reading about and i someone told me with arrays i have to use a heapsort so i have to read that as well.

getting an error for Teams new and goals new.it say new is an invalid expression

error for void in open file and read file.syntax error insert enumbody to complete

block statement. insert enum identifier. "void" @ expected. its really raw.

import java.io.*;
import java.util.*;

public class Football {
	
	public static void main(String[] args){
		
		boolean  enter;
		int counter = 0;
		char reply;
		String Teams[];
		int goals[];
		int points[];
		int temp;
		String temps;
		
		
		
		System.out.println("Please choose one of the following options");
		System.out.println("Option 1:Start Tournament");
		System.out.println("Option 2:End Program");
		
		
		
		if(enter == 1){
			
			System.out.println("round one starts");
			
			
			
			for(int i = 0; i <= 7; i++){
				System.out.println("Segment: x+1");
				
				Teams = new [32];

				goals = new [5];
				
				for(int j = 0; j <=2; j++){
					goals[counter] = 5 + rand()% (10-5 +1);
					System.out.println(goals[counter]);
					
				}
			}
		}
		
		for(int i = 0; (i <= 31); i++)
	     {
				          for (int j=0; j < 31; j++)
	         {
	               if (goals[j+1] > goals[j] & Teams[j+1] > Teams[j])      // ascending order simply changes to <
	              {
	                     temps =  Teams[j];             // swap elements
	                     Teams[j] =  Teams[j+1];
	                     Teams[j+1] = temps;

	                    temp = goals[j];             // swap elements
	                    goals[j] = goals[j+1];
	                    goals[j+1] = temp;
	                                // indicates that a swap occurred.

	               }
	          }
	     }

		
		public Teams(String Teams){
			
		}
		
		
		private Scanner x;
		
		public void openFile(){
			try{
				x = new Scanner(new File("tournament.txt"));
			}
			
			catch(Exception e){
				System.out.println("could not find file");
			}
		}
		
		public void readFile(){
			while(x.hasNext()){
				String a = File.next();
			}
		}
	}

}

Teams = new [32]; (etc)
You have to say what it is that you have a new 32 element array of, eg
myCharArray = new char[32];

ps Next time, don't just post bits of the compiler error message, post all of it INCLUDING the source code line number where the error was detected.

ok i read about queues which is what i am using so i redid it in a queue but this is what i have so far. now i want to know if it is suppose to read the info from a file where is that going and i am suppose to have a sorting algorithm and i am trying a selection sort but where do i insert that plus i have to output the results to a file with the info where is that going. don't know how to get the line numbers as well.

public class SoccerCup {
	
	
	public class Node{
		
		
		public Team info;
		public Node link;
		
		
		public Node(){
			
			info = null;
			link = null;
			
		}
		
		class Team{
			
			public String teamName = "xxxx";
			public int points = 0;
			public int goalsFor = 0;
			public int goals =0;
			public int goalsAgainst = 0;
			public boolean adv2= false;
			public boolean adv3= false;
			public boolean adv4= false;
			
			
			public Team(String teamName, int points, int goalsFor, int goals, int goalsAgainst, boolean adv2, boolean adv3, boolean adv4){
				
				this.teamName = teamName;
				this.points = points;
				this.goalsFor = goalsFor;
				this.goals = goals;
				this.goalsAgainst = goalsAgainst;
				this.adv2 = adv2;
				this.adv3 = adv3;
				this.adv4 = adv4;
				
			}

			
			
			
			
		}
		
	}
	
	private int queueSize;
	Node queueFront;
	Node queueBack;
	
	
	public SoccerCup(){
		
		queueSize = 0;
		queueFront = null;
		queueBack = null;
		
		
		
	}
	
	public void enqueue(Node.Team info){
		
		Node newNode = new Node();
		newNode.info = info;
		
		
		if(isEmpty()){
			
			queueFront = newNode;
			queueBack = newNode;
			newNode.link = null;
		}
		else{
			
			queueBack.link = newNode;
			queueBack = newNode;
			newNode.link = null;
		}
			queueSize++;
		
	}
	
	public boolean isEmpty(){
		
		return (queueFront == null);
	}
	
	public int getQueueSize(){
		
		return queueSize;
	}
	
	public void dequeue(){
		
		if(isEmpty()){
			
			System.err.println("\n\n Sorry! Cannot print from empty queue!\n\n\n");
		}
		else{
			Node front = queueFront;
			queueFront = queueFront.link;
			front = null;
			System.gc();
			queueSize--;
		}
	}
	
	void front(){
		
		if(isEmpty()){
			
			System.err.println("\n\n Sorry! Cannot print from empty queue!\n\n\n");	
		}
		else{
			
			System.out.println(queueBack.info);
		}
	}

}

beside the help i am requesting for the above code i need to know how to make a welcome scree and to use a math object to create random numbers for the goals

ok i redid some stuff and made a mess of the main i am still missing the sorting and recieved a lot of errors.
line 10 saying team cannot be resolved.
line 27 saying group is a duplicate local variable.
line 31 scan cannot be resolved.
line 38 invalid cannot be resolved.
line 39 this type of expression must be resolved to an array but it rsolved to a string group[count-1] = group.
it is also saying that matchplayed, goalsfor, goalsagainst cannot be resolved. here is the code.

public class SoccerCup {
	
	
	public class Node{
		
		
		public Team info;
		public Node link;
		
		
		public Node(){
			
			info = null;
			link = null;
			
		}
		
		class Team{
			
			public String teamName = "xxxx";
			public int points = 0;
			public int goalsFor = 0;
			public int goals =0;
			public int goalsAgainst = 0;
			public boolean adv2= false;
			public boolean adv3= false;
			public boolean adv4= false;
			
			
			public Team(String teamName, int points, int goalsFor, int goals, int goalsAgainst, boolean adv2, boolean adv3, boolean adv4){
				
				this.teamName = teamName;
				this.points = points;
				this.goalsFor = goalsFor;
				this.goals = goals;
				this.goalsAgainst = goalsAgainst;
				this.adv2 = adv2;
				this.adv3 = adv3;
				this.adv4 = adv4;
				
			}

			
			
			
			
		}
		
	}
	
	private int queueSize;
	Node queueFront;
	Node queueBack;
	
	
	public SoccerCup(){
		
		queueSize = 0;
		queueFront = null;
		queueBack = null;
		
		
		
	}
	
	public void enqueue(Node.Team info){
		
		Node newNode = new Node();
		newNode.info = info;
		
		
		if(isEmpty()){
			
			queueFront = newNode;
			queueBack = newNode;
			newNode.link = null;
		}
		else{
			
			queueBack.link = newNode;
			queueBack = newNode;
			newNode.link = null;
		}
			queueSize++;
		
	}
	
	public boolean isEmpty(){
		
		return (queueFront == null);
	}
	
	public int getQueueSize(){
		
		return queueSize;
	}
	
	public void dequeue(){
		
		if(isEmpty()){
			
			System.err.println("\n\n Sorry! Cannot print from empty queue!\n\n\n");
		}
		else{
			Node front = queueFront;
			queueFront = queueFront.link;
			front = null;
			System.gc();
			queueSize--;
		}
	}
	
	void front(){
		
		if(isEmpty()){
			
			System.err.println("\n\n Sorry! Cannot print from empty queue!\n\n\n");	
		}
		else{
			
			System.out.println(queueBack.info);
		}
	}

}
import java.util.*;
import java.util.Scanner;


public class TestSoccerCup {
	
	//Team variables
	int TeamCount;
	int teamWins;
	public static  Team team;
	private String teamName;
	public static int matchesPlayed;
	public static int matchPoints;
	public static int totalGoalsFor;
	public static int totalGoalsAgainst;
	
	public static void main(String[] args){
		
		
		final Scanner console = new Scanner (System.in);
		
		String[] group = new String[4];
		int count = 1;
		while(count <= group.length)
		{
			boolean valid = false;
			String group = "";
			do
			{
				System.out.print("Add group #"+count+": ");
				group = scan.nextLine();
				if(group.length() == 0){
					System.out.print("invalid group!");
						}
				else
					valid = true;
			}
			while(!invalid);
			group[count-1] = group;
			count++;
			}
		
			        System.out.println("Your Group:"); 
		        for(int i=0; i< group.length; i++)
		        {
		        	System.out.println("\t"+group[i]);
		        	
		        }
		        	

		}
	
	public void enqueue()
	{
		Scanner scan = new Scanner(System.in);
		String[] teams = new String[4];
		int count = 1;
		
		while(count <= teams.length)
		{
		            boolean valid = false; 
			        String gruop = ""; 
		         do
		         {
	                System.out.print("Add Team #"+count+": "); 
		        	group = scan.nextLine(); 
		        	if(group.length() == 0){ 
		        	      System.out.print("Invalid team!"); 

		         }
		        	else
		        		valid = true;
		         
		         }
		         
		         while(!invalid);
		         teams[count-1] = group;
		         count++;
		         
		        System.out.println("Group A:"); 
		      	for(int i=0; i< teams.length; i++) 
		 	    { 
		   	      System.out.println("\t"+teams[i]); 
		  } 
		        System.out.println("Group B:"); 
		      	for(int i=0; i< teams.length; i++) 
		 	    { 
		   	      System.out.println("\t"+teams[i]); 
		  } 
		     
		        
		        System.out.println("Group C:"); 
		      	for(int i=0; i< teams.length; i++) 
		 	    { 
		   	      System.out.println("\t"+teams[i]); 
		  } 
		     
		     
		        
		        System.out.println("Group D:"); 
		      	for(int i=0; i< teams.length; i++) 
		 	    { 
		   	      System.out.println("\t"+teams[i]); 
		  } 
		     
		        
		        System.out.println("Group E:"); 
		      	for(int i=0; i< teams.length; i++) 
		 	    { 
		   	      System.out.println("\t"+teams[i]); 
		  } 
		      	
		      	 System.out.println("Group F:"); 
			      	for(int i=0; i< teams.length; i++) 
			 	    { 
			   	      System.out.println("\t"+teams[i]); 
			  } 
			      	
			      	 System.out.println("Group G:"); 
				      	for(int i=0; i< teams.length; i++) 
				 	    { 
				   	      System.out.println("\t"+teams[i]); 
				  }
				      	
				      	 System.out.println("Group H:"); 
					      	for(int i=0; i< teams.length; i++) 
					 	    { 
					   	      System.out.println("\t"+teams[i]); 
					  } 
					      	
					      	
					 public String getTeamName(String teamName)
					 {
						 return teamName;
					 }
					 
					 public int getMatchPoints()
					 {
						 return matchpoints;
					 }
					 
					 public int getGoalsFor()
					 {
						 return goalsFor;
					 }
					 
					 public int getGoalsAgainst()
					 {
						 return GoalsAgainst;
					 }
					 
					 public int getMatchesPlayed()
					 {
						 return MatchesPlayed;
					 }
					 
					 
					 	      
			      
					       //Set methods 
		
		   public boolean setTeamName()
		{ 
					      	        
	        return true; 
	   } 
	   
	    public void setMatchPoints() 
	   { 
	      this.matchPoints=0; 
	    }        
	     public void setGoalsFor() 
	   { 
	      this.GoalsFor=0; 
	   } 
    public void setGoalsAgainst() 
	  { 
		this.GoalsAgainst=0; 
	  } 
	    public void setMatchesPlayed() 
	    { 
	       this.matchesPlayed=0; 
	    } 
					      	   
					      
	   //Increment Matches Played 
		    public int incrementMatchesPlayed(int matchesPlayed) 
	  { 
	      this.matchesPlayed=matchesPlayed + matchesPlayed; 
		      return this.matchesPlayed; 
	      } 
					      		        
		   //Increment Matches Points 
			      public int incrementMatchPoints(int matchPoints);
			{ 
		 this.matchPoints=matchPoints + matchPoints; 
	        return this.matchPoints; 
		      } 
	       //Increment Goals For 
			       public int incrementGoalsFor (int GoalsFor) 
		       { 
	           this.GoalsFor=GoalsFor + GoalsFor; 
		           return this.GoalsFor; 
					      } 
		   //Increment Goals Against 
			        public int incrementGoalsAgainst(int GoalsAgainst) 
			        { 
	            this.GoalsAgainst=GoalsAgainst + GoalsAgainst; 
		          return this.GoalsAgainst; 
		        } 
					      		     
					      		       
		     //toString method 
			    public String toString() 
			    { 
		        return teamName + ", "+ matchPoints + ", "+ GoalsFor + ", " + GoalsAgainst + ", ";                      
			   }      
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.