I am trying to pass a value to an attribute of the class that I created in Java but it just won't work.
Here is my code :
// Landscape Class
public class Landscape{
// Attribute
char [] [] landscape ;
// Constructor to create the landscape
public void Landscape(){
landscape = {
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'},
{'^',' ',' ',' ',' ','^','^','^','^',' ',' ',' ',' ','^','^','^'},
{'^',' ','^','^',' ',' ',' ','^','^',' ','^','^','^','^','^','^'},
{'^',' ',' ','^',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
{'^','^',' ','^',' ','^',' ','^','^','^','^','^','^','^','^','^'},
{'^',' ',' ',' ',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
{'^','^',' ',' ','^','^',' ','^','^',' ',' ',' ',' ','^','^','^'},
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'}
};
}
// Function to display the landscape
public void display(){
System.out.println("");
for(char [] element : landscape){
System.out.print(" ");
for(char character : element){
System.out.print(character);
}
System.out.println("");
}
System.out.println("");
}
public static void main(String[] args){
Landscape landscape = new Landscape();
landscape.display();
}
}
I have already chacked my array syntax and I know it's fine but for some reasons it seems that Java can't recognize my class attribute and gives me all these crazy errors :
Landscape.java:13: error: illegal start of expression
landscape = {
^
Landscape.java:15: error: not a statement
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:15: error: ';' expected
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:15: error: illegal start of expression
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:16: error: not a statement
{'^',' ',' ',' ',' ','^','^','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:16: error: ';' expected
{'^',' ',' ',' ',' ','^','^','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:16: error: illegal start of expression
{'^',' ',' ',' ',' ','^','^','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:17: error: not a statement
{'^',' ','^','^',' ',' ',' ','^','^',' ','^','^','^','^','^','^'},
^
Landscape.java:17: error: ';' expected
{'^',' ','^','^',' ',' ',' ','^','^',' ','^','^','^','^','^','^'},
^
Landscape.java:17: error: illegal start of expression
{'^',' ','^','^',' ',' ',' ','^','^',' ','^','^','^','^','^','^'},
^
Landscape.java:18: error: not a statement
{'^',' ',' ','^',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:18: error: ';' expected
{'^',' ',' ','^',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:18: error: illegal start of expression
{'^',' ',' ','^',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:19: error: not a statement
{'^','^',' ','^',' ','^',' ','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:19: error: ';' expected
{'^','^',' ','^',' ','^',' ','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:19: error: illegal start of expression
{'^','^',' ','^',' ','^',' ','^','^','^','^','^','^','^','^','^'},
^
Landscape.java:20: error: not a statement
{'^',' ',' ',' ',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:20: error: ';' expected
{'^',' ',' ',' ',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:20: error: illegal start of expression
{'^',' ',' ',' ',' ',' ',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:21: error: not a statement
{'^','^',' ',' ','^','^',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:21: error: ';' expected
{'^','^',' ',' ','^','^',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:21: error: illegal start of expression
{'^','^',' ',' ','^','^',' ','^','^',' ',' ',' ',' ','^','^','^'},
^
Landscape.java:22: error: not a statement
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'}
^
Landscape.java:22: error: ';' expected
{'^','^','^','^','^','^','^','^','^','^','^','^','^','^','^','^'}
^
24 errors
I would like to understand what I did wrong and how to fix it