hey, friends : )
after learning the basics of Objects, I wanted to try to make an own practice project, which should be simple
but somehow I dont have the expected outcome
what I got is:
class team with this variable and function to create new agents
public static agent[] members = new agent[3];
public static void setAgents() throws IOException {
System.out.println("You can create up to 3 Agents for " + name);
for (int i = 0; i < members.length; i++){
members[i] = new agent();
members[i].setName();
System.out.println("Name: " + (members[i].getName())); //this returns the correct name of the created agent
}
}
Which should create 1 agent object for each array-member
class agent looks like this (variables and function to set/get the name
public class agent {
public static String name;
public static int HP;
public static int ATK;
public static int DEF;
public static boolean isAlive = true;
public void setName() throws IOException {
System.out.println("Hi, please type in the name for your agents:");
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
name = reader.readLine();
}
public static String getName() throws IOException {
return name;
}
but when I try to show all the agents of the team afterwards, only the name of the last added agent is shown
public static void showTeam () throws IOException {
System.out.println("This is your current team");
for (int i = 0; i < members.length; i++){
System.out.println("Agent 0" + i);
System.out.println("--------------------");
}
}
can someone please help me, seems like I didnt understand the Basics of Objects fully : (
thanks in advance : )