Hello!
I've been busy passing exams, but now I'm free to code around again.
So, in my usual style!
The goal:
I've been playing some Battlefield 3 during study breaks, and I've often been pissed off by BF3's autobalance mechanism. It's bad. Horrible. It makes me sad. I usually have to watch cat videos for an hour to recover from being autobalanced.
But, it gave me the idea to code my own autobalancer! :D
The problem:
To me, my logic seems fine, but the code breaks when I try to call the methods and objects in my main class.
The code (Player.class):
package autobalance;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
public class Player {
private Random R = new Random();
private String name;
private int team;
private int score;
List<Player> allPlayers;
public Player() {
this.name = "Soldier ";
this.score = this.R.nextInt(10000);
this.team = this.R.nextInt(2) + 1;
}
public Player addPlayer(String soldierName) {
this.allPlayers = new ArrayList<>();
Player P = new Player();
P.setName(this.name + soldierName);
allPlayers.add(P);
return P;
}
public void showTeam(int T) {
Iterator<Player> IT = this.allPlayers.iterator();
while (IT.hasNext()) {
Player temp = IT.next();
if (temp.getTeam() == T) {
System.out.println(temp.getName() + "-" + temp.getScore());
}
}
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getScore() {
return score;
}
public int getTeam() {
return team;
}
}
The code (main Autobalance.class):
package autobalance;
public class Autobalance {
public static void main(String[] args) {
Player P = new Player();
P.addPlayer("Mirza");
P.addPlayer("Asmir");
P.addPlayer("Ljubo");
P.addPlayer("Slađo");
P.addPlayer("Khan");
P.addPlayer("Vpa");
P.addPlayer("Marin");
System.out.println("Team 1:");
P.showTeam(1);
System.out.println("Team 2:");
P.showTeam(2);
}
}
Error report:
No red lines in the code, but when I run it, this happens:
Exception in thread "main" java.lang.RuntimeException:
Uncompilable source code - constructor Player in class autobalance.
Player cannot be applied to given types;
required: no arguments
found: java.lang.String
reason: actual and formal argument lists differ in length
at autobalance.Autobalance.main(Autobalance.java:5)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 s
It says line 5 in Autobalance.class is broken, does that mean all of Player.class is broken? :S
I'd really appreaciate gurus' help. :)