jeudi 20 avril 2017

JAVA: using NEW variable value from different class

Dears, I´m new in java and I was wondering if I can write a code that is going to get exact value of a new variable from different class. I would like to let the int calculate variable monsters.

ORG int //private static int monsterexp = elliador.monsters.getExp(monsters.exp);/ I would like to let it count by specific monster: private static int monsterexp = elliador.monsters.getExp(monsters.zombie.exp); If you would also share a technique how to identify the "variable" variable into the code it would be awesome (i mean that I wouldn´t have to write zombie in it, but it would choose zombie or hydra depending on the other void that will choose the monster). Probably I´m mixing alltogether... Thank you very much for your support.

package elliador;

import elliador.monsters;


class source {

private String name;
private static int experience;
private static int attack;
private static int defense;
private static int magic;


private static int monsterexp = elliador.monsters.getExp(monsters.exp);
private static int countofcreatures = 25;
private static int earnexp = countofcreatures * monsterexp;



public source(String name,int experience, int attack, int defense, int magic) {

    this.name = name;
    this.experience = experience;
    this.attack = attack;
    this.defense = defense;
    this.magic = magic;

}

public void myhero() {
    System.out.println("Name: " + getName() + " Experience: " + getExperience() + " Attack: " + getAttack() + " Defense: " + getDefense() + " Magic: " + getMagic());
}

public String getName() {
    return name;
}

public void setName() {
    this.name = name;
}

public int getExperience() {
    return experience;
}

public void setExperience() {
    this.experience = experience + earnexp;
}

public int getAttack() {
    return attack;
}

public void setAttack() {
    this.attack = attack + 1;
}

public int getMagic() {
    return magic;
}

public void setMagic() {
    this.magic = magic + 1;

}

public int getDefense() {
    return defense;
}

public void setDefense() {
    this.defense = defense + 1;
}

}

class monsters

package elliador;

import elliador.heroes;

class monsters {

private String name;
private static int attack;
private static int defense;
private static int magic;
public static int exp;

public monsters(String name, int attack, int defense, int magic, int exp) {

    this.name = name;
    this.attack = attack;
    this.defense = defense;
    this.magic = magic;
    this.exp = exp;

}

//*how to use specific monster in the int mentioned in description?*/
public static int getExp (int exp) {
monsters zombie = new monsters("zombie",1,0,0,1);
monsters hydra = new monsters("Hydra",20,12,3,2);

return monsters.exp;

}



public static int getAttack (int attack) {

monsters zombie = new monsters("zombie",1,0,0,1);


//*monsters hydra = new monsters("Hydra",20,12,3,1);
return monsters.attack;
}

}

class heroes

package elliador;

import elliador.monsters;

public class heroes {

  public static void main (String[] args) throws InterruptedException {
    source Olsen;
    Olsen = new source("Olsen",0,1,1,1);



    Integer i = new Integer(5);
    Integer i2 = new Integer (5);
    System.out.println(i.equals(i2));
    Olsen.myhero();
    Olsen.setExperience();
    Olsen.myhero();
    Olsen.setExperience();
    Olsen.myhero();
    Olsen.setAttack();
    Olsen.setMagic();
    Olsen.myhero();       
    }

    }






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire