0

I am working on my final project in my OOP1 class. The language is java.

I'd like to know how I invoke the following method inside my constructor:

public Garden (int size)    {

    garden=new char[size][size];

    this.initializeGarden(garden[][]);
}


private void intializeGarden(char [][]garden)   {

    for(int i=0;i<garden.length;i++)
        for(int j =0;j<garden.length;j++)
            garden[i][j]='-';

}

this.initializeGarden(garden[][]); is one of several failed attempts. I've tried a few variations, and eclipse didn't like any of them.

4

3 Answers 3

2
public class Garden {
char[][] garden;

public Garden (int size)    {

    garden=new char[size][size];

    this.initializeGarden(garden);
}


private void initializeGarden(char [][]garden)   {

    for(int i=0;i<garden.length;i++)
        for(int j =0;j<garden.length;j++)
            garden[i][j]='-';

}

public void display(){
    for(int i=0;i<garden.length;i++){
        for(int j =0;j<garden.length;j++){
            System.out.print(garden[i][j]);
        }
        System.out.println();
    }


}


public static void main(String[] args) {
    new Garden(20).display();
}
}
Sign up to request clarification or add additional context in comments.

Comments

0

Your private method intializeGarden appears to have a typo in it.

So the call would look like intializeGarden(garden)

1 Comment

Yes, I saw that after posting. Thanks :) Well, at least I was not totally out to lunch. "Hmm, this should work" Yeah it does, when you spell things right!
0

Simply change

this.initializeGarden(garden[][]);

to

this.initializeGarden(garden);

The above code will pass the garden variable as an argument to the initializeGarden method.

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.