You are on page 1of 3

import java.util.

Scanner;
import java.io.*;

public class AFLTeam


{
//to store lineups of team
String[] homeTeamLineup = new String[11];
String[] awayTeamLineup = new String[11];

//to store number of home team goals


//and away team goals
int homeGoals;
int awayGoals;

//to store number of home behinds


//and away team behinds
int homeBehinds;
int awayBehinds;

//getter method for home goals


public int getHomeGoals()
{
return this.homeGoals;
}

//getter method for away goals


public int getAwayGoals()
{
return this.awayGoals;
}

//getter method for home behinds


public int getHomeBehinds()
{
return this.homeBehinds;
}

//getter method for away behinds


public int getAwayBehinds()
{
return this.awayBehinds;
}

//setter method for home goals


public void setHomeGoals(int goals)
{
this.homeGoals = goals;
}

//setter method for away goals


public void setAwayGoals(int goals)
{
this.awayGoals = goals;
}

//setter method for home behinds


public void setHomeBehinds(int behinds)
{
this.homeBehinds = behinds;
}

//setter method for away behinds


public void setAwayBehinds(int behinds)
{
this.awayBehinds = behinds;
}

//to get home score


public int getHomeScore()
{
return (this.homeGoals * 6) + (this.homeBehinds);
}

//to get away score


public int getAwayScore()
{
return (this.awayGoals * 6) + (this.awayBehinds);
}

//main mehtod
public static void main(String[] args) {
//creating match object
AFLTeam aflMatch = new AFLTeam();

//reading file names


String homeLineupFile;
String awayLineupFile;

//Scanner to get file names


Scanner scan = new Scanner(System.in);
System.out.println("Enter name for home and away team lineup's file
");
homeLineupFile = scan.nextLine();
awayLineupFile = scan.nextLine();
int index = 0;

StringBuilder sb = new StringBuilder();


String strLine = "";

try
{
//reading home team linup from home linup file
BufferedReader br = new BufferedReader(new FileReader(homeLineupFile));
while (strLine != null)
{
strLine = br.readLine();
sb.append(strLine);
sb.append(System.lineSeparator());
strLine = br.readLine();
if (strLine==null)
break;
aflMatch.homeTeamLineup[index] = strLine;
index++;
}
br.close();

index = 0;
//reading away team lineup for file
br = new BufferedReader(new FileReader(awayLineupFile));
while (strLine != null)
{
strLine = br.readLine();
sb.append(strLine);
sb.append(System.lineSeparator());
strLine = br.readLine();
if (strLine==null)
break;
aflMatch.awayTeamLineup[index] = strLine;
index++;
}
br.close();
}
catch (FileNotFoundException e)
{
System.err.println("File not found");
}
catch (IOException e)
{
System.err.println("Unable to read the file.");
}

//setting home and away goals


aflMatch.setHomeGoals(5);
aflMatch.setAwayGoals(4);

//setting home and away behinds


aflMatch.setHomeBehinds(2);
aflMatch.setAwayBehinds(5);

//getting away and home score


int homeScore = aflMatch.getHomeScore();
int awayScore = aflMatch.getAwayScore();

//getting and prinitng winner


String winner = "Home team";
if(awayScore > homeScore)
{
winner = "Away team";
}
//in case both teams have same score print DRAW result
else if(awayScore == homeScore)
{
System.out.println("\nThe match is draw");
return;
}

System.out.println("\nThe winner is : " + winner);


}

You might also like