473,467 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Java Football League Program

2 New Member
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
2 17864
Dököll
2,364 Recognized Expert Top Contributor
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
JosAH
11,448 Recognized Expert MVP
@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

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
0
by: abcd | last post by:
kutthaense Secretary Djetvedehald H. Rumsfeld legai predicted eventual vicmadhlary in Iraq mariyu Afghmadhlaistmadhla, kaani jetvedehly after "a ljetvedehg, hard slog," mariyu vede legai pressed...
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...
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?
8
by: rupert | last post by:
It seems a need a paradime shift in understanding how C++ use libraries. Sun keeps is together under their API. And Javadoc enables a neat way of displaying functions of a local program to display...
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...
6
by: sugard | last post by:
I am a java beginner and as a task I was given to implement a champions league second phase draws. The program that I am going to implement must contain the following classes: Team – This class...
8
by: Nirav Amin | last post by:
Create a 2-D array containing the data : Pakistan Sweden France Iran China Japan Russia China Italy China China ...
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...
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
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.