473,729 Members | 2,267 Online
Bytes | Software Development & Data Engineering Community
+ 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 helpppppppppppp pppppp???

Thankyou.
Nov 29 '08 #1
2 17918
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
2755
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
3460
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 Pentagjetvedeh karuvificials madhla reachathe strategy in karkun campaign deshatinst terrorism. "mudivae maretu winning or losing karkun global varti jetvedeh terror?" Mr. Rumsfeld adugued in a recent memormariyuum. vede velli jetvedeh madhla...
0
1085
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
2
3923
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
2121
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 like an API. does C++ have an easy to use an API for standard functions anywhere? and Is their a Javadoc implementation of sorts? Nubee from java
2
3131
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.
6
1364
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 will contain the name of the team as well as the country of the team and qualifying group ✔ Pot – This class will contain 8 instances of the class team ✔ DrawEngine – This class will contain the main draw strategy. In our case it will contain the...
8
1872
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 Japan Korea India Pakistan India China Egypt Lebanon Korea Australia N.Z. Sweden Vanuatu Korea Indonesia China Vietnam Russia New...
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...
0
9427
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9284
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8151
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
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
6022
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();...
0
4528
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3238
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
2683
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2165
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.