Football league
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Taranjit_Matharu
Posted On:   Monday, April 28, 2003 10:06 AM

Hi, iv written a football league code, that creates a team (array of objects) the program requests the amount of teams, creates the number of teams, and prints them out. What i wanted to do next was make a fixture list, so the teams play each other twice, but not eachother. And when each draw is made, i can input the scores for each team. I have tried many different methods such as accessor, mutator methods, double for loops, but i can't get it to wotk. This is my code so far, it works fine. import java.io.*; class League1 { public static void main (String[] args) throws IOException { String team; int points; BufferedReader stdin; stdin =   More>>

Hi, iv written a football league code, that creates a team (array of objects) the program requests the amount of teams, creates the number of teams, and prints them out.

What i wanted to do next was make a fixture list, so the teams play each other twice, but not eachother. And when each draw is made, i can input the scores for each team. I have tried many different methods such as accessor, mutator methods, double for loops, but i can't get it to wotk. This is my code so far, it works fine.




import java.io.*;


class League1 {


public static void main (String[] args) throws IOException {


String team;
int points;


BufferedReader stdin;
stdin = new BufferedReader(new InputStreamReader (System.in));
System.out.print ("How many teams are to enter your league? ");
System.out.flush();
int numteams = Integer.parseInt(stdin.readLine());


Team[] teams = new Team[numteams];


for (int i = 0; i < teams.length; i++) {
teams[i] = new Team();
}


for (int i = 0; i < teams.length; i++) {
System.out.print ("Enter team name: ");
System.out.flush();
team = stdin.readLine();
teams[i].setTeam(team);
System.out.print ("Enter team points: ");
System.out.flush();
points = Integer.parseInt(stdin.readLine());
teams[i].setPoints(points);
}


for (int i = 0; i < teams.length; i++) {
System.out.println("Same value?" +(teams[i].equals(teams[i])));
}


for (int i = 0; i < teams.length; i++) {
teams[i].displayTable();
}
}
}


class Team {


String Teamname;
int Teampoints;


public Team () {
Teamname = " ";
Teampoints = 0;
}


void setTeam (String team) {
Teamname = team;
}


void setPoints (int points) {
Teampoints = points;
}


void displayTable () {
System.out.println (Teamname + "'s points: ");
System.out.print(Teampoints + " points");
System.out.println();
}
}


Any ideas? Thanks

   <<Less

Re: Football league

Posted By:   Benoit_Quintin  
Posted On:   Monday, April 28, 2003 12:57 PM

So I assume that you and this guy go to the same school... What school is that? (so that I can tell your teacher that he/she should do his/her job and help you guys...)
About | Sitemap | Contact