473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Football League Program

2
Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2. import java.util.Collections;
  3.  
  4. public class Test {
  5.  
  6.     public static void main (String [] arg) {
  7.     //                     "012345678910" alignment guide 
  8.     String [] results = {  "AR  4 BR  5",
  9.                            "CR  0 DR  1",
  10.                            "AR 10 CR  9",
  11.                            "BR  3 DR  1",
  12.                            "AR  0 DR  2",
  13.                            "BR  2 AR  2",
  14.                            "BR  0 CR  5",
  15.                            "CR  1 BR  3",
  16.                            "CR  4 AR  2",
  17.                            "DR  1 AR  1",
  18.                            "DR  2 BR  1",
  19.                            "DR  0 CR  2",
  20.  
  21.                            "ES  2 FO  2",
  22.                            "GR  0 HE  0",
  23.                            "FO  1 GR  2",
  24.                            "HE  3 ES  5",
  25.                            "ES  4 GR  3",
  26.                            "ES  0 HE  2",
  27.                            "GR  1 FO  3",
  28.                            "GR  2 ES  1",
  29.                            "FO  2 HE  1",
  30.                            "FO  3 ES  3",
  31.                            "HE  1 FO  0",
  32.                            "HE  2 GR  1"};                    
  33.  
  34.  
  35.  
  36.     League myLeague = new League();
  37.     myLeague.setupDiv1();
  38.     myLeague.setupDiv2();
  39.     for(String r: results){
  40.     myLeague.addResult(r);    
  41.     }// end for each r    
  42.  
  43.     myLeague.print(); 
  44.     Arrays.sort(results);
  45.     myLeague.print();
  46.     //myLeague.testFindTeam("DR");
  47.  
  48.  
  49.     } //end method main ()
  50.  
  51.  
  52.  
  53. }// end class Test
  54.  
  55.  
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.util.Arrays;
  3. import java.util.Vector;
  4. import java.util.Collections;
  5.  
  6. public class League {
  7.  
  8.     Vector<Team> teams;
  9.  
  10.     String [] list1 = {"AR Arad", "BR Braila", "CR Craiova", "DR Drobeta"};
  11.     String [] list2 = {"ES Escandov", "FO Foscani", "GR Gronstadt", "HE Hermansburg"};
  12.  
  13.  
  14.     public League() {
  15.     teams = new Vector<Team>();
  16.     }// end constructor League()
  17.  
  18.     public void setupDiv1 () {
  19.     for (int i=0; i<list1.length; i++) {
  20.         String code = list1[i].substring(0,2);
  21.         String name = list1[i].substring(3);
  22.         addTeam(1, code, name);
  23.     } //end for i
  24.     }// end method setupDiv1 ()
  25.  
  26.  
  27.     public void setupDiv2 () {
  28.     for (int i=0; i<list2.length; i++) {
  29.         String code = list2[i].substring(0,2);
  30.         String name = list2[i].substring(3);
  31.         addTeam(2, code, name);
  32.     } //end for i
  33.     }// end method setupDiv2 ()
  34.  
  35.  
  36.     public void addTeam (int division, String code, String name) {
  37.     Team aTeam = new Team(division, code, name);
  38.     teams.add(aTeam);
  39.     }// end method addTeam()
  40.  
  41.     public Team findTeam(String code) {
  42.         Team aTeam = null;
  43.         for (int i=0; i<teams.size(); i++) {
  44.             aTeam = teams.get(i);
  45.             if (aTeam.code.equals (code))break;
  46.         }// end for i
  47.         return aTeam;
  48.     }//end method findTeam()
  49.  
  50.     public void testFindTeam(String code) {
  51.     Team aTeam = findTeam(code);
  52.     System.out.println("Found Team = "+aTeam.name);
  53.     }//end method findTeam()
  54.  
  55.  
  56.     public void addResult(String result){
  57.     String hCode = "AR";
  58.     String aCode = "BR";
  59.     int hScore = 4;
  60.     int aScore = 5;
  61.     //         "01234567890" alignment guide 
  62.     //result = "AR  4 BR  5"
  63.     hCode = result.substring(0,2).trim();
  64.     aCode = result.substring(6,8).trim();
  65.  
  66.     String hS = result.substring(3,5).trim();
  67.     String aS = result.substring(9).trim();
  68.  
  69.     hScore = Integer.parseInt(hS);
  70.     aScore = Integer.parseInt(aS);
  71.  
  72.     Team homeTeam = this.findTeam(hCode);
  73.     homeTeam.addHomeResult(hScore,aScore);
  74.  
  75.     Team awayTeam = this.findTeam(aCode);
  76.     awayTeam.addAwayResult(hScore,aScore);
  77.  
  78.  
  79.     }//end method addResult() 
  80.  
  81.     public void print() {
  82.         for (Team aTeam: teams) {
  83.             aTeam.print();
  84.  
  85.         }// end forall teams
  86.     }// end method print()
  87.  
  88. }// end class League
  89.  
Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.*;
  3. import java.util.Collections;
  4. import java.util.Comparator;
  5.  
  6. public class Team implements Comparable <Team> {
  7.  
  8. int division;
  9. String name;
  10. String code;
  11. int points;
  12. int played;
  13. int scored;
  14. int conceded;
  15. int difference;
  16.  
  17. public int compareTo(Team aTeam){
  18. //if 
  19. return 0;
  20. }//end method compareTo() 
  21.  
  22. public Team(int division, String code, String name) {
  23. this.division = division;
  24. this.code = code;
  25. this.name = name;
  26. }// end constructor Team(code, name)
  27.  
  28. public void addResult(int home, int away) {
  29. // home and away are goals score by home and away teams in a match
  30. }// end method addResult()
  31.  
  32. public void addHomeResult(int home, int away) {
  33. if (home==away) points = points + 1;  // Draw
  34. if (home > away) points = points + 2; // Home Win
  35. //if (home < away) points = points + 3; // Away Win
  36. played++;
  37. scored = scored + home;
  38. conceded = conceded + away;
  39. difference = scored - conceded;
  40. }// end method addHomeResult()
  41.  
  42. public void addAwayResult(int home, int away) {
  43. if (home==away) points = points + 1;  // Draw
  44. //if (home > away) points = points + 2; // Home Win
  45. if (home < away) points = points + 3; // Away Win
  46. played++;
  47. scored = scored + home;
  48. conceded = conceded + away;
  49. difference = scored - conceded;
  50. }// end method addAwayResult()
  51.  
  52. public void print() {
  53. System.out.println("DIV"+"\t"+"CODE"+"\t"+"POINTS"+"\t"+"PLAYED"+"\t"+"SCORED"+"\t"+"CONC"+"\t"+"DIFF");
  54. System.out.println(division+"\t"+code+"\t"+points+"\t"+played+"\t"+scored+"\t"+conceded+"\t"+difference+"\t");
  55.  
  56. } //end method print()
  57.  
  58. }// end class Team
  59.  


How can i sort my data with regards to the total number of points, im having difficulty with that!!

can someone help, thanksssssssss
Dec 2 '08 #1
4 7640
JosAH
11,448 Expert 8TB
@minus
Have a look at the Comparator interface and the Collections.sort() or Arrays.sort() methods. btw, your 's' key seems to be stuck; fix that.

kind regards,

Jos
Dec 2 '08 #2
Nepomuk
3,112 Expert 2GB
Actually, the OP's already using that in the class Team - but just look at your compareTo method:
Expand|Select|Wrap|Line Numbers
  1. public int compareTo(Team aTeam){
  2. //if 
  3. return 0;
  4. }//end method compareTo() 
Do you know, what this method should be doing?

Greetings,
Nepomuk
Dec 2 '08 #3
JosAH
11,448 Expert 8TB
@Nepomuk
No he isn't; he's using the Comparable interface. A Comparator interface is easier when you want to sort on different criteria.

kind regards,

Jos
Dec 2 '08 #4
Nepomuk
3,112 Expert 2GB
Ah, sorry, you're right and I'm wrong. I should read more carefully. ^^

Greetings,
Nepomuk
Dec 2 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Domestos | last post by:
Hi all, Does anybody know of a fantasy football application written in php/mysql I could purchase and run a league with? Thanks Andrew Makinson
1
by: Lynda McEwan | last post by:
I am having difficulty in writing a league program for a family member. I wrote a similar program many years ago in turbo pascal but am at a loss with vb. I will get there in the end but has anyone...
6
by: binger | last post by:
Okay, Superbowl is only a few days away, but I thought it would be cool to set up an online registration for a football squares pool. My thoughts are to have people go into anywhere on the 10x10...
0
by: BrainKr | last post by:
Still have 4 openings in our CBS SportsLine.com Fantasy Football league. Champ wins $200 prize. If interested, go to: http://football.sportsline.com/splash/football Register for the GOLD...
3
by: Ram | last post by:
Hi, I am trying to set up a DB for a race series where a riders best 6 of 10 rides count towards a league position. I have a table of Riders ( say 300 ) I want to use a form to select which...
2
by: edwgib2002 | last post by:
Does anyone have any information related to a scheduling algorithm that can be written in VBA and used in an access database to create balanced team schedules for a league?
2
by: steve.falzon | last post by:
Hi Folks The new footy season is almost with us, in England anyway :) I've just created a public league on the Times **FREE** fantasy football league game so if anyone wants to join up please...
3
by: Ben Bacarisse | last post by:
Bert <albert.xtheunknown0@gmail.comwrites: <snip> Do you have an example of a "slow" data set. Obviously I can make my own, but such puzzles often come with data sets. I have a simple...
2
by: minus | last post by:
public class Test { public static void main (String arg) { // "012345678910" alignment guide String results = {"AR 4 BR 5", "CR 0 DR 1",...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.