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

java beginner

P: 50
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 two instances of class Pot. It will be responsible to implement the rules
of the draw (country checking etc.)
✔ Draw This class contains the two teams drawn against each other. Your
application should finally produce eight instances of this class.

The rules for the champions league game are the following:

 Teams coming from the same country may not be picked up against each other.
 Teams from the same group may not be drawn against each other.

I started implementing the Team class and I have done the following:

public class Team {

String name;
String country;
Double luckFactor;
Double strength;

Team TeamsInPot1 = new Team[8];

teamInPot1[0] = new Team ("Manchester United");
teamInPot1[1] = new Team ("Real Madrid");
teamInPot1[2] = new Team ("Liverpool");
teamInPot1[3] = new Team ("Milan");
teamInPot1[4] = new Team ("Inter");
teamInPot1[5] = new Team ("Birkirkara");
teamInPot1[6] = new Team ("Barcelona");
teamInPot1[7] = new Team ("Brussels");

teamInPot1[0].country = "England";
teamInPot1[1].country = "Germany";
teamInPot1[2].country = "England";
teamInPot1[3].country = "Italy";
teamInPot1[4].country = "Italy";
teamInPot1[5].country = "Malta";
teamInPot1[6].country = "Spain";
teamInPot1[7].country = "Belgium";

Team TeamsInPot2 = new Team[8];

teamInPot2[0] = new Team ("Chelsea");
teamInPot2[1] = new Team ("Juventus");
teamInPot2[2] = new Team ("Lisbona");
teamInPot2[3] = new Team ("Leeds");
teamInPot2[4] = new Team ("SKV ");
teamInPot2[5] = new Team ("Berlin ");
teamInPot2[6] = new Team ("Paris");
teamInPot2[7] = new Team ("Valletta");

teamInPot2[0].country = "England";
teamInPot2[1].country = "Italy";
teamInPot2[2].country = "Portugal";
teamInPot2[3].country = "England";
teamInPot2[4].country = "Austria";
teamInPot2[5].country = "Germany";
teamInPot2[6].country = "France";
teamInPot2[7].country = "Malta";
}


The problem now is that I dont know how am i going to randomly generate the countries and make them obey the rules that i gave i.e. no teams of the same countries are placed against each other.

any help would be very appreciated.

thanku
Aug 8 '07 #1
Share this Question
Share on Google+
6 Replies


10K+
P: 13,264
Write the required classes as per the specs first. Remember things that you define to be inside a class have to satisfy the has-a relationship.
e.g Team has a name - correct makes sense.
Team has a Team ??? doesn't make sense.
I repeat my first sentence here for convenience:
Write the required classes as per the specs first.



P.S I hope ManU get drawn against Barcelona.
Aug 8 '07 #2

P: 50
the required classes are Draw, DrawEngine and Pot.

public class Draw {

}

public class DrawEngine {

}

public class Pot {

}
Aug 8 '07 #3

Expert 10K+
P: 11,448
the required classes are Draw, DrawEngine and Pot.

public class Draw {

}

public class DrawEngine {

}

public class Pot {

}
As per your assignment text: a Draw has two teams. etc. You're supposed to
fill in that information as well.

kind regards,

Jos
Aug 8 '07 #4

P: 50
how am i going to insert the 2 teams in draw?

As per your assignment text: a Draw has two teams. etc. You're supposed to
fill in that information as well.

kind regards,

Jos
Aug 8 '07 #5

10K+
P: 13,264
how am i going to insert the 2 teams in draw?
Your specs have really spoiled it all for you. The first step is to obey them. If they say a Team has a country, then define a country in the Teams class. If they say a Draw has two teams, then you need two instances of the Teams class in there. That means you need to have compiled the Team class successfully first.
Aug 8 '07 #6

Expert 10K+
P: 11,448
how am i going to insert the 2 teams in draw?
Spoiler alert:

Expand|Select|Wrap|Line Numbers
  1. public class Draw {
  2.    private Team teamA;
  3.    private Team teamB;
  4.    //
  5.    public Draw(Team teamA, Team teamB) {
  6.       this.teamA= teamA;
  7.       this.teamB= teamB;
  8.    }
  9.    ...
  10. }
  11.  
Now you have to craft your other classes in a similar way. That would result in
the skeletons of the classes you are about to use in your application. You have
to make some choices as well: e.g. for the Draw class, should it accept two
teams from the same country or is something else figuring that out?

kind regards,

Jos
Aug 8 '07 #7

Post your reply

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