Re: Football Betting System
Next step will be for you to design the program you need and write some code.
Come back here when you have problems.
Re: Football Betting System
here is some code on 20 football teams that need to be randomly met with a 1,2, X rating and the score you think im doing ok as i am very new to java
thanks
public static void main(String args[])
Teams teams[]=new team[20];
teams[0]=(Arsenal,8);
teams[1]=(AstonVilla,7);
teams[2]=(Blackburn,6);
teams[3]=(Bolton,6);
teams[4]=(Chelsea,8);
teams[5]=(Everton,7);
teams[6]=(Fulham,6);
teams[7]=(Liverpool,8);
teams[8]=(ManchesterCity,8);
teams[9]=(ManchesterUnited,9);
teams[10]=(Newcastle,7);
teams[11]=(Norwich,4);
teams[12]=(QPR,4);
teams[13]=(Stoke,6);
teams[14]=(Sunderland,6);
teams[15]=(Swansea,4);
teams[16]=(Tottenham,7);
teams[17]=(WBA,5);
teams[18]=(Wigan,5);
teams[19]=(Wolves,5);
public string probability(team a,team b){
if(a.getrating==b.getrating)
return "x";
if(a.getrating>b.getrating)
return"1";
else
return"2"
}
team t1;
team t2;
int t1goals=-1
int t2goals=-1
java.util.Random
private void generate random score(){
Random r=new random();
t1goals=r.next int(7);
t2goals=r.next int(7);
}
Re: Football Betting System
Regarding the code you typed in:
You'd need a definition for the Teams class.
The syntax is not valid. You create Team objects with: new Team("name", rating)
Do you have any ideas of what the program should do to implement the steps you listed in post #1?
Re: Football Betting System
Hi norm i added some more code not sure what i am doing wrong and thanks for your help
package betting;
public class Team {
private String name; //name of team
private int rating = 0;
//constructor of class Team
public Team(String name, int rating) {
super();
this.name = name;
this.rating = rating;
}
//returns the name of the team
public String getName() {
return name;
}
//sets the name of the team
public void setName(String name) {
this.name = name;
}
//returns the rating of the team
public int getRating() {
return rating;
}
// sets the rating of the team to the new parameter
public void setRating(int rating) {
this.rating = rating;
}
//toString method to return whenever a team is called
public String toString() {
return "Team " + name + ", rating = " + rating;
}
}
public static void main(String args[])
Teams teams[]=new team[20];
teams[0]=(Arsenal,8);
teams[1]=(AstonVilla,7);
teams[2]=(Blackburn,6);
teams[3]=(Bolton,6);
teams[4]=(Chelsea,8);
teams[5]=(Everton,7);
teams[6]=(Fulham,6);
teams[7]=(Liverpool,8);
teams[8]=(ManchesterCity,8);
teams[9]=(ManchesterUnited,9);
teams[10]=(Newcastle,7);
teams[11]=(Norwich,4);
teams[12]=(QPR,4);
teams[13]=(Stoke,6);
teams[14]=(Sunderland,6);
teams[15]=(Swansea,4);
teams[16]=(Tottenham,7);
teams[17]=(WBA,5);
teams[18]=(Wigan,5);
teams[19]=(Wolves,5);
public string probability(team a,team b){
if(a.getrating==b.getrating)
return "x";
if(a.getrating>b.getrating)
return"1";
else
return"2"
}
team t1;
team t2;
int t1goals=-1
int t2goals=-1
java.util.Random
private void generate random score(){
Random r=new random();
t1goals=r.next int(7);
t2goals=r.next int(7);
}
public BetResult getResult() {
generateRandomScore();//generate actual score
//returning 1,2 or X according to actual result
String res;
if (t1Goals == t2Goals) {
res = "X";
} else if (t1Goals > t2Goals) {
res = "1";
} else {
res = "2";
}
return new BetResult(res, t1Goals, t2Goals);
}
Re: Football Betting System
Please wrap your posted code in code tags to preserver formatting. See: BB Code List - Java Forums
Did you read my comments in post#4 about the syntax for creating Team objects?
What errors do you get when you compile your program? Please copy and paste them here.