0

I have an object of type 'Bee' which I want to add to my arraylist cells in my class hive but I'm getting a compilation error "Bee cannot be resolved to a variable" on the sidebar in eclipse in my getBee method and I am not really sure if my addBee method is good or not.

My code:

import java.util.ArrayList;
public class Hive {

    ArrayList<Bee> cells = new ArrayList<Bee>();
    int Honey = 10;
    int RoyalJelly = 10;
    int Pollen = 10;    

    public void addBee(Bee b){
        cells.add(b);
    }

    public Bee getBee(int n){
        if(n < cells.size()){
            cells.get(n);
            return Bee;
        }else{
            return null;
        }
    }

    public int size(){
        return cells.size();
    }

    public void addHoney(int h){
        Honey = Honey + h;
    }

    public void addRoyalJelly(int r){
        RoyalJelly = RoyalJelly + r;
    }

    public void addPollen(int p){
        Pollen = Pollen + p;
    }

    public int takeHoney(int h2){
        if(h2 <= Honey){
            Honey = Honey - h2;
            return h2;
        }else{
            return 0;
        }
    }

    public int takeRoyalJelly(int r2){
        if(r2 <= RoyalJelly){
            RoyalJelly = RoyalJelly - r2;
            return r2;
        }else{
            return 0;
        }
    }

    public int takePollen(int p2){
        if(p2 <= Pollen){
            Pollen = Pollen - p2;
            return p2;
        }else{
            return 0;
        }
    }

    public void anotherDay(){

    }

}

1 Answer 1

1

Your syntax is incorrect here:

if(n < cells.size()){
    cells.get(n);
    return Bee;
}else{

You don't return the class name. Just return the result of the call to get:

if(n < cells.size()){
    return cells.get(n);
}else{
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.