473,895 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Football League Program

2 New Member
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 7673
JosAH
11,448 Recognized Expert MVP
@minus
Have a look at the Comparator interface and the Collections.sor t() or Arrays.sort() methods. btw, your 's' key seems to be stuck; fix that.

kind regards,

Jos
Dec 2 '08 #2
Nepomuk
3,112 Recognized Expert Specialist
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 Recognized Expert MVP
@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 Recognized Expert Specialist
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
2764
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
1733
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 done something similar which is available on shareware or public domain?
6
3673
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 matrix and put their name in. If someone already has put their name in a square, then the text input box is now static (i.e. cant be overwritten)... Only problem - I'm not sure how to do this. I'd plan on using an
0
1095
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 Fantasy Football, then search for and join the "Rocky Mountain PigSkinners" league. Automated draft is on September 5th. Plenty of time for the druggies to
3
3861
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 riders from the Riders Table are taking part and create a new Event Table ( say Round 1 ) max of 120 riders per event.
2
3940
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
3137
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 do. My league is called Red Dwarf Crew and it's public so no password needed.
3
281
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 solution and I like to see if really is as bad as your tutor suggests. Also I would not mind some more test data...
2
17944
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", "AR 10 CR 9", "BR 3 DR 1", "AR 0 DR 2", "BR 2 AR 2",
0
9990
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9836
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10937
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10473
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
8028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7179
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4693
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4288
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3298
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.