pretty much I've made a program that goes a little like this
- Players are added to an array
- they are then all placed against each other(just like a football match, every team plays every team)
- They are then randomized
- the program should display the end result(if you win a game you get 3 points) etc..
I keep getting a message from Eclipse saying ".setScore has NOT been coded..
TestGame.java
public class TestGame {
static Players ceri = new Players("Ceri", 0);
static Players harry = new Players("Harry", 0);
static Players matthew = new Players("Matthew", 0);
static Players james = new Players("James",0);
static Players kwok = new Players("Kwok",0);
static Players lewis = new Players("Lewis",0 );
static Game League = new Game();
int Ceri = 0;
public static void main(String[] args) {
League.addPlayers(ceri);
League.addPlayers(matthew);
League.addPlayers(james);
League.addPlayers(kwok);
League.addPlayers(lewis);
League.addPlayers(harry);
League.randomize();
League.Results();
}
}
Game.java
public class Game extends TestGame {
Scanner s = new Scanner(System.in);
private Players[] people = new Players[6];
private int counter = 0;
List<String> Matches = new ArrayList<String>();
public void addPlayers(Players obj){
people[counter] = obj;
counter++;
System.out.println(obj.getName());
}
public String randomize(){
for(int i = 0; i < people.length; i++){
for(int j = i + 1; j < people.length; j++){
if(people[i].equals(people[j].getName())){
continue;
} else {
Matches.add(people[i].getName() + " V " + people[j].getName());
}
}
}
return null;
}
public String Results(){
while(!Matches.isEmpty()){
int Game = (int)(Math.random() * Matches.size());
String Verses = (String)Matches.get(Game);
System.out.println(Verses);
System.out.println("Who has won?");
String name = s.nextLine();
//**ISSUE LIES HERE**
if(Verses.contains(name)){
if(name == "ceri"){
ceri.setScore(3);
} else if(name == "harry"){
harry.setScore(3);
}else if (name == "matthew"){
matthew.setScore(3)
} else if(name == "lewis"){
lewis.setScore(3)
}else if ( name == "james"){
james.setScore(3)
}else if(name == "kwok"){
kwok.setScore(3);
}
}
Matches.remove(Game);
System.out.println(one);
return null;
}
return null;
}
}
WHERE ECLIPSE SAYS .setScore ISNT.
Players.java
public class Players {
private String name;
private int score;
public Players(String name, int score){
this.name = name;
this.score = score;
}
public String getName(){
return this.name;
}
public int getScore() {
return this.score;
}
public void setScore(int score) {
this.score =+ score;
}
}