I'm need to set up teams based on how many wins the team has inside this text file :
UNCC 30
NCSU 28
GT 25
USC 20
GSU 19
UVA 15
UGA 2
UNC 1
For example the output of the program should be:
UNCC VS UNC
NCSU VS UGA
GT VS UVA
USC VS GSU
This is my code:
import java.io.*;
import java.util.Scanner;
public class Tournmanet
{
public static void main(String [] args) throws IOException
{
File file = new File("Teams.txt");
Scanner input = new Scanner(file);
String w;
int wins;
String teamName;
int gameCounter=0;
Teams [] game = new Teams [8];
for (int i= 0; i < game.length; i++)
{
teamName = input.next();
w= input.next();
wins= Integer.parseInt(w);
game[i] = new Teams(teamName, wins);
}
for (int i = 0; i < game.length-1; i+=2)
{
for(int j= 0; j< game.length; j+=2)
{
if(i > game.length)
j--;
System.out.println(game[i+1].getName()+ " VS." + game[j].getName());
}
}
}
}
class Teams
{
String teamName;
int wins;
public Teams()
{
}
public Teams (String teamName, int wins)
{
this.teamName = teamName;
this.wins = wins;
}
public String getName()
{
return teamName;
}
public int getWins()
{
return wins;
}
}
THIS IS THE OUTPUT I GET:
NCSU VS.UNCC
NCSU VS.GT
NCSU VS.GSU
NCSU VS.UGA
USC VS.UNCC
USC VS.GT
USC VS.GSU
USC VS.UGA
UVA VS.UNCC
UVA VS.GT
UVA VS.GSU
UVA VS.UGA
UNC VS.UNCC
UNC VS.GT
UNC VS.GSU
UNC VS.UGA
Any ideas? Thanks!