By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,190 Members | 1,555 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,190 IT Pros & Developers. It's quick & easy.

Java Football League Program

P: 2
Expand|Select|Wrap|Line Numbers
  1.  
  2. public class Test {
  3.  
  4.     public static void main (String [] arg) {
  5.     //                   "012345678910" alignment guide 
  6.     String [] results = {"AR  4 BR  5",
  7.                          "CR  0 DR  1",
  8.                          "AR 10 CR  9",
  9.                          "BR  3 DR  1",
  10.                          "AR  0 DR  2",
  11.                          "BR  2 AR  2",
  12.                          "BR  0 CR  5",
  13.                          "CR  1 BR  3",
  14.                          "CR  4 AR  2",
  15.                          "DR  1 AR  1",
  16.                          "DR  2 BR  1",
  17.                          "DR  0 CR  2",
  18.  
  19.                          "ES  2 FO  2",
  20.                          "GR  0 HE  0",
  21.                          "FO  1 GR  2",
  22.                          "HE  3 ES  5",
  23.                          "ES  4 GR  3",
  24.                          "ES  0 HE  2",
  25.                          "GR  1 FO  3",
  26.                          "GR  2 ES  1",
  27.                          "FO  2 HE  1",
  28.                          "FO  3 ES  3",
  29.                          "HE  1 FO  0",
  30.                          "HE  2 GR  1"};                    
  31.  
  32.  
  33.  
  34.     League myLeague = new League();
  35.     myLeague.setupDiv1();
  36.     myLeague.setupDiv2();
  37.     for(String r: results){
  38.     myLeague.addResult(r);    
  39.     }// end for each r    
  40.  
  41.     myLeague.print(); 
  42.     //myLeague.testFindTeam("DR");
  43.  
  44.  
  45.     } //end method main ()
  46.  
  47.  
  48.  
  49. }// end class Test
  50.  
  51.  



Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.Vector;
  3. import java.util.Collections;
  4.  
  5. public class League {
  6.  
  7.     Vector<Team> teams;
  8.  
  9.     String [] list1 = {"AR Arad", "BR Braila", "CR Craiova", "DR Drobeta"};
  10.     String [] list2 = {"ES Escandov", "FO Foscani", "GR Gronstadt", "HE Hermansburg"};
  11.  
  12.     public League() {
  13.     teams = new Vector<Team>();
  14.     }// end constructor League()
  15.  
  16.     public void setupDiv1 () {
  17.     for (int i=0; i<list1.length; i++) {
  18.         String code = list1[i].substring(0,2);
  19.         String name = list1[i].substring(3);
  20.         addTeam(1, code, name);
  21.     } //end for i
  22.     }// end method setupDiv1 ()
  23.  
  24.  
  25.     public void setupDiv2 () {
  26.     for (int i=0; i<list2.length; i++) {
  27.         String code = list2[i].substring(0,2);
  28.         String name = list2[i].substring(3);
  29.         addTeam(2, code, name);
  30.     } //end for i
  31.     }// end method setupDiv2 ()
  32.  
  33.  
  34.     public void addTeam (int division, String code, String name) {
  35.     Team aTeam = new Team(division, code, name);
  36.     teams.add(aTeam);
  37.     }// end method addTeam()
  38.  
  39.     public Team findTeam(String code) {
  40.         Team aTeam = null;
  41.         for (int i=0; i<teams.size(); i++) {
  42.             aTeam = teams.get(i);
  43.             if (aTeam.code.equals (code))break;
  44.         }// end for i
  45.         return aTeam;
  46.     }//end method findTeam()
  47.  
  48.     public void testFindTeam(String code) {
  49.     Team aTeam = findTeam(code);
  50.     System.out.println("Found Team = "+aTeam.name);
  51.     }//end method findTeam()
  52.  
  53.  
  54.     public void addResult(String results){
  55.     String hCode = "AR";
  56.     String aCode = "BR";
  57.     int hScore = 4;
  58.     int aScore = 5;
  59.  
  60.     Team homeTeam = this.findTeam(hCode);
  61.     homeTeam.addHomeResult(hScore,aScore);
  62.  
  63.     Team awayTeam = this.findTeam(aCode);
  64.     awayTeam.addAwayResult(hScore,aScore);
  65.     }//end method addResult() 
  66.  
  67.     public void print() {
  68.         for (Team aTeam: teams) {
  69.             aTeam.print();
  70.         }// end forall teams
  71.     }// end method print()
  72.  
  73. }// end class League
  74.  
  75.  


Expand|Select|Wrap|Line Numbers
  1.  
  2. import java.util.Collections;
  3. import java.util.Comparator;
  4.  
  5. public class Team implements Comparable <Team>  {
  6.  
  7. int division;
  8. String name;
  9. String code;
  10. int points;
  11. int played;
  12. int scored;
  13. int conceded;
  14. int difference;
  15.  
  16. public int compareTo(Team aTeam){
  17.  
  18. return 0;
  19. }//end method compareTo() 
  20.  
  21. public Team(int division, String code, String name) {
  22. this.division = division;
  23. this.code = code;
  24. this.name = name;
  25. }// end constructor Team(code, name)
  26.  
  27. public void addResult(int home, int away) {
  28. // home and away are goals score by home and away teams in a match
  29. }// end method addResult()
  30.  
  31. public void addHomeResult(int home, int away) {
  32. if (home==away) points = points + 1;  // Draw
  33. if (home > away) points = points + 2; // Home Win
  34. //if (home < away) points = points + 3; // Away Win
  35. played++;
  36. scored = scored + home;
  37. conceded = conceded + away;
  38. difference = scored - conceded;
  39. }// end method addHomeResult()
  40.  
  41. public void addAwayResult(int home, int away) {
  42. if (home==away) points = points + 1;  // Draw
  43. //if (home > away) points = points + 2; // Home Win
  44. if (home < away) points = points + 3; // Away Win
  45. played++;
  46. scored = scored + home;
  47. conceded = conceded + away;
  48. difference = scored - conceded;
  49. }// end method addAwayResult()
  50.  
  51. public void print() {
  52. System.out.println("DIV"+"\t"+"CODE"+"\t"+"POINTS"+"\t"+"PLAYED"+"\t"+"SCORED"+"\t"+"CONC"+"\t"+"DIFF");
  53. System.out.println(division+"\t"+code+"\t"+points+"\t"+played+"\t"+scored+"\t"+conceded+"\t"+difference+"\t");
  54. } //end method print()
  55.  
  56. }// end class Team
  57.  
  58.  

I have three classes: Test, League and Team

My program needs to display the champions of each division (1 and 2)
Display the names of the two teams that are being promoted/relegated.

I am having problems adding each result and then letting the program update the statistics for each team.

Can someone please helpppppppppppppppppp???

Thankyou.
Nov 29 '08 #1
Share this Question
Share on Google+
2 Replies


Dököll
Expert 100+
P: 2,364
Hopefully this is not homework, but thanks for posting your code...

I would say search here for answers on how to add variables and make available a result.

You could do something like this:

Expand|Select|Wrap|Line Numbers
  1.    //Return the total payment
  2.     public double getFinalPayment() {
  3.         double totalPayment;
  4.         totalPayment = weeklyPay() + comissionPayment() + overtimePayment();
  5.         return totalPayment;
  6.     }
  7.  
  8.  
Good luck with the project!
Dec 1 '08 #2

Expert 10K+
P: 11,448
@Dököll
That reply and the code snippet have nothing to do with the OP's problem. Please don't confuse people.

kind regards,

Jos
Dec 1 '08 #3

Post your reply

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