Java 扩展类没有';我似乎没有继承一些数据

Java 扩展类没有';我似乎没有继承一些数据,java,inheritance,Java,Inheritance,我有三类,有机体,生物和植物生物和植物都扩展了有机体。现在,当所有东西都捆绑到有机体中时,这段代码就工作了,所以我假设GUI类没有错。基本上,正在发生的只是生成特定的生物统计信息,而生物统计信息被忽略,返回0。我没发现有什么问题,所以我想你们可以帮忙。(别理这些乱七八糟的东西,我还在玩。) 生物类 导入java.awt.Color; 导入java.util.Random; 公营生物 { 私人性别; 私人智力力量、速度、饮食、攻击性; 私有整数匹配,最大匹配; 公共生物() { 超级(); Ran

我有三类,
有机体
生物
植物
<代码>生物和
植物
都扩展了
有机体
。现在,当所有东西都捆绑到
有机体中时,这段代码就工作了,所以我假设GUI类没有错。基本上,正在发生的只是生成特定的
生物
统计信息,而
生物
统计信息被忽略,返回
0
。我没发现有什么问题,所以我想你们可以帮忙。(别理这些乱七八糟的东西,我还在玩。)

生物类
导入java.awt.Color;
导入java.util.Random;
公营生物
{
私人性别;
私人智力力量、速度、饮食、攻击性;
私有整数匹配,最大匹配;
公共生物()
{
超级();
Random rand=新的Random();
if(rand.nextInt(2)==0)
{
性别=‘f’;
}
其他的
{
性别='m';
}
交配=0;
setStats();
}
公共生物(字符串生成器[])
{
超级(gen);
Random rand=新的Random();
if(rand.nextInt(2)==0)
{
性别=‘f’;
}
其他的
{
性别='m';
}
x=随机数nextInt(maxX);
y=兰特·奈克斯汀(maxY);
setStats();
}
公共生物(字符串gen[],int newX,int newY)
{
超级(gen、newX、newY);
这个基因=基因;
Random rand=新的Random();
if(rand.nextInt(2)==0)
{
性别=‘f’;
}
其他的
{
性别='m';
}
isAlive=真;
x=newX;
y=新的;
setStats();
}
public int getAggro()
{
回归侵略;
}
公共饮食
{
回归饮食;
}
public int getSpeed()
{
返回速度;
}
公共无效设置状态()
{
强度=(基因[1]。特征(0)-48)+1+((基因[1]。特征(1)-48)*(基因[1]。特征(2)-48));
速度=(强度+(基因[2]。字符(0)-48)-(基因[2]。字符(1)-48)+(基因[2]。字符(2)-48))/(大小+1);
饮食=(基因[7]。性状(0)-48)+1+((基因[7]。性状(1)-48)*(基因[7]。性状(2)-48)*(3/4));
攻击性=((强度+大小)/2/(基因[8]。特征(0)-48+基因[8]。特征(1)-48+基因[8]。特征(2)-48+1);
maxHealth=64+尺寸+(强度/2);
最大饥饿=100+(大小-速度-攻击性);
健康=最大健康;
饥饿=最大饥饿;
}
公共生物品种(生物伴侣)
{
Random rand=新的Random();
int x=rand.nextInt(基因长度);
int y=rand.nextInt(基因[x].length());
字符串geneY[]=新字符串[16];
int i;
对于(i=0;i1 | | this.gender==org.gender | | | mated==maxMated | | org.mated==org.maxMated)
{
返回false;
}
返回true;
}
公共无效移动到(组织)
{
int vectX,vectY,moveX=0,moveY=0;
双角度;
vectX=this.x-org.x;
vectY=this.y-org.y;
如果(vectX==0)
{
moveY=这个速度;
}
如果(向量==0)
{
moveX=这个速度;
}
if(vectX==0&&vectY==0)
{
moveX=0;
moveY=0;
}
如果(vectX!=0&&vectY!=0)
{
角度=((Math.atan((vectY)/(vectX))/(2*Math.PI))*360;
如果(角度<0)
{
角度=角度*-1;
}
moveX=(int)(数学sin(角度)*这个速度);
moveY=(int)(数学cos(角度)*这个速度);
}
if(Math.sqrt((vectX*vectX)+(vectY*vectY))0)
{
this.x=this.x-vectX;
}
其他的
{
this.x=this.x+vectX;
}
如果(向量>0)
{
this.y=this.y-向量;
}
其他的
{
this.y=this.y+向量;
}
}
其他的
{
如果(vectX>0)
{
this.x=this.x-moveX;
}
其他的
{
this.x=this.x+moveX;
}
如果(向量>0)
{
this.y=this.y-moveY;
}
其他的
{
this.y=this.y+moveY;
}
}
}
}
生物类
导入java.awt.Color;
导入java.util.Random;
公营生物
{
受保护字符串基因[]=新字符串[16];
保护生命;
受保护的int x;
保护智力;
公共关系
import java.awt.Color;
import java.util.Random;


public class Creature extends Organism
{
    private char gender;
    private int strength, speed, diet, aggression;
    private int mated, maxMated;

    public Creature()
    {
        super();
        Random rand = new Random();
        if(rand.nextInt(2) == 0)
        {
            gender = 'f';
        }
        else
        {
            gender = 'm';
        }
        mated = 0;
        setStats();
    }

    public Creature(String gen[])
    {
        super(gen);
        Random rand = new Random();
        if(rand.nextInt(2) == 0)
        {
            gender = 'f';
        }
        else
        {
            gender = 'm';
        }
        x = rand.nextInt(maxX);
        y = rand.nextInt(maxY);
        setStats();
    }

    public Creature(String gen[], int newX, int newY)
    {
        super(gen, newX, newY);
        this.gene = gen;
        Random rand = new Random();
        if(rand.nextInt(2) == 0)
        {
            gender = 'f';
        }
        else
        {
            gender = 'm';
        }
        isAlive = true;
        x = newX;
        y = newY;
        setStats();
    }

    public int getAggro()
    {
        return aggression;
    }

    public int getDiet()
    {
        return diet;
    }

    public int getSpeed()
    {
        return speed;
    }

    public void setStats()
    {
        strength = (gene[1].charAt(0)-48) + 1 + ((gene[1].charAt(1)-48) * (gene[1].charAt(2)-48));
        speed = (strength + (gene[2].charAt(0)-48) - (gene[2].charAt(1)-48) + (gene[2].charAt(2)-48))/(size + 1);
        diet = (gene[7].charAt(0)-48) + 1 + ((gene[7].charAt(1)-48) * (gene[7].charAt(2)-48)*(3/4));
        aggression = ((strength + size)/2) / (gene[8].charAt(0)-48 + gene[8].charAt(1)-48 + gene[8].charAt(2)-48 + 1);

        maxHealth = 64 + size + (strength / 2);
        maxHunger = 100 + (size - speed - aggression);

        health = maxHealth;
        hunger = maxHunger;
    }

    public Creature breed(Creature mate)
    {
        Random rand = new Random();
        int x = rand.nextInt(gene.length);
        int y = rand.nextInt(gene[x].length());
        String geneY[] = new String[16];
        int i;
        for(i = 0; i < x; i++)
        {
            geneY[i] = gene[i];
        }
        geneY[x] = gene[x].substring(0,y);
        geneY[x] = geneY[x] + mate.gene[x].substring(y);
        for(i = x + 1; i < 16; i++)
        {
            geneY[i] = mate.gene[i];
        }

        char newGender;
        if(rand.nextInt(2) == 0)
        {
            newGender = 'f';
        }
        else
        {
            newGender = 'm';
        }

        hunger = hunger /2;
        mate.hunger = mate.hunger /2;
        mated = mated + 1;
        mate.mated = mate.mated + 1;

        Creature temp = new Creature(geneY,this.getX(),this.getY());
        temp.mutate();
        return temp;        
    }

    public void eat(Organism b) //A eats B
    {
        b.isAlive = false;
        this.hunger = this.hunger + b.size;
    }

    public boolean isCompatible(Creature org)
    {
        int differences = 0;
        for(int i = 0; i < this.gene.length; i++)
        {
            if(!this.gene[i].equals(org.gene[i]))
            {
                differences = differences + 1;
            }
        }
        if(differences > 1 || this.gender == org.gender || mated == maxMated || org.mated == org.maxMated)
        {
            return false;
        }
        return true;
    }

    public void moveTo(Organism org)
    {
        int vectX, vectY, moveX = 0, moveY = 0;
        double angle;

        vectX = this.x - org.x;
        vectY = this.y - org.y;

        if(vectX == 0)
        {
            moveY = this.speed;
        }
        if(vectY == 0)
        {
            moveX = this.speed;
        }
        if(vectX == 0 && vectY == 0)
        {
            moveX = 0;
            moveY = 0;
        }
        if(vectX != 0 && vectY != 0)
        {
            angle = ((Math.atan((vectY)/(vectX)))/(2*Math.PI))*360;
            if(angle < 0)
            {
                angle = angle * - 1;
            }
            moveX = (int)(Math.sin(angle)*this.speed);
            moveY = (int)(Math.cos(angle)*this.speed);
        }

        if(Math.sqrt((vectX*vectX)+(vectY*vectY)) < speed)
        {
            if(vectX > 0)
            {
                this.x = this.x - vectX;
            }
            else
            {
                this.x = this.x + vectX;
            }

            if(vectY > 0)
            {
                this.y = this.y - vectY;
            }
            else
            {
                this.y = this.y + vectY;
            }
        }
        else
        {
            if(vectX > 0)
            {
                this.x = this.x - moveX;
            }
            else
            {
                this.x = this.x + moveX;
            }

            if(vectY > 0)
            {
                this.y = this.y - moveY;
            }
            else
            {
                this.y = this.y + moveY;
            }
        }

    }

}
import java.awt.Color;
import java.util.Random;


public class Organism 
{
    protected String gene[] = new String[16];
    protected boolean isAlive;
    protected int x;
    protected int y;
    protected int size, sense, fertility, scent;
    protected int health, hunger, maxHealth, maxHunger;
    protected int maxX = 1000;
    protected int maxY = 1000;
    private Color color = new Color(255,0,0);

    public Organism()
    {
        Random rand = new Random();
        for(int i = 0; i < 16; i++)
        {
            gene[i] = ""+ rand.nextInt(4) + rand.nextInt(4) + rand.nextInt(4);  
        }
        isAlive = true;
        x = rand.nextInt(maxX);
        y = rand.nextInt(maxY);
        setStats();
    }

    public Organism(String gen[])
    {
        Random rand = new Random();
        this.gene = gen;
        isAlive = true;
        x = rand.nextInt(maxX);
        y = rand.nextInt(maxY);
        setStats();
    }

    public Organism(String gen[], int newX, int newY)
    {
        this.gene = gen;
        isAlive = true;
        x = newX;
        y = newY;
        setStats();
    }

    public Color getColor()
    {
        return color;
    }

    public int getX()
    {
        return x;
    }

    public void setX(int tempX)
    {
        this.x = tempX;
    }

    public int getY()
    {
        return y;
    }

    public void setY(int tempY)
    {
        this.y = tempY;
    }

    public int getHunger()
    {
        return hunger;
    }

    public void setHunger(int hun)
    {
        this.hunger = hun;
    }

    public int getHealth()
    {
        return health;
    }

    public void setHealth(int heal)
    {
        this.health = heal;
    }

    public void setStats()
    {
        size = (gene[0].charAt(0)-48) + 1 + ((gene[0].charAt(1)-48) * (gene[0].charAt(2)-48));
        sense = (gene[5].charAt(2)-48) + 1 + ((gene[5].charAt(1)-48) * (gene[5].charAt(2)-48));
        fertility = 22 - size + (gene[6].charAt(0)-48) + 1 + ((gene[6].charAt(1)-48) * (gene[6].charAt(2)-48));
        scent = (gene[8].charAt(0)-48 + gene[8].charAt(1)-48 + gene[8].charAt(2)-48);
    }

    public int getSize()
    {
        return size;
    }

    public int getSense()
    {
        return sense;
    }

    public boolean getAlive()
    {
        return isAlive;
    }

    public void setAlive(boolean live)
    {
        this.isAlive = live;
    }

    public String getInfo()
    {
        String info;
        info = "Health: " + this.health + ", Hunger: "+ this.hunger + ", Status: " + this.isAlive;
        return info;
    }

    /*public String getStats()
    {
        String info = "Size: " + this.size + ", Strength: " + this.strength +
                ", Speed: " + this.speed + ", Sight: " + this.sight +
                ", Smell: " + this.smell + ", Hearing: " + this.hearing +
                ", Fertility: " + this.fertility + ", Diet: " + this.diet +
                ", Aggression: " + this.aggression + ", Scent: " + this.scent;
        return info;            
    }*/

    public String displayGene()
    {
        String geneP = "|";
        for(int i = 0; i < gene.length; i++)
        {
            for(int j = 0; j < gene[i].length(); j++)
            {
                switch (gene[i].charAt(j))
                {
                    case '0': geneP = geneP + 'A';
                    break;
                    case '1': geneP = geneP + 'T';
                    break;
                    case '2': geneP = geneP + 'C';
                    break;
                    case '3': geneP = geneP + 'G';
                    break;
                }
            }           
            geneP = geneP + "|";
        }
        return geneP;
    }

    public void mutate()
    {
        Random rand = new Random();
        int i = rand.nextInt(10000) + 1;
        int affected;
        if(i > 9999)
        {
            affected = rand.nextInt(gene.length);
            i = rand.nextInt(gene[affected].length());
            int j = rand.nextInt(4);
            gene[affected] = gene[affected].substring(0,i)+j+gene[affected].substring(i+1);     
        }
    }

    public void hungerCheck()
    {
        hunger = hunger - (size / 10 + 1);
        if(hunger <= 0)
        {
            health = health - 1;
        }
        if(hunger > (maxHunger * 3)/4)
        {
            health = health + 1;
        }
    }

    public void validate()
    {       
        if(x > maxX)
        {
            x = 100;
        }
        if(x < 0)
        {
            x = 0;
        }
        if(y > maxY)
        {
            y = 100;
        }
        if(y < 0)
        {
            y = 0;
        }

        if(hunger > maxHunger)
        {
            hunger = maxHunger;
        }
        if(hunger <= 0)
        {
            hunger = 0;
        }
        if(health <= 0)
        {
            isAlive = false;
        }
        if(health > maxHealth)
        {
            health = maxHealth;
        }
    }
}
public class Creature extends Organism
    public void setStats()
    {
        super.setStats(); // Call to Organism.setStats()
        ...


    }
    ....
}