What am I doing wrong?

import java.io.*;// needed for BufferedReader, InputStreamReader, etc.

/** A Java program that calculates transport routes. */

class Routefinder

{

// Create a single shared BufferedReader for keyboard input

privatestatic BufferedReader stdin =

new BufferedReader(new InputStreamReader( System.in ) );

// variable declarations

{

String fromioroutes[];

String toioroutes[];

String nioroutes[];

String[] Places =new String[11];

Places[0] ="Airport";

Places[1] ="Church";

Places[2] ="Well-to-do Estate";

Places[3] ="CBD";

Places[4] ="Hospital";

Places[5] ="Grungy Neighborhood";

Places[6] ="Middle Class Suburbs";

Places[7] ="Police Station";

Places[8] ="Fire Station";

Places[9] ="Old Market";

Places[10] ="Mall";

String Airport_ioroutes=("R");

String Church_ioroutes=("R1, A4, B5");

String Church_nioroutes=("A3, A5");

String WelltodoEstate_ioroutes=("R2, A5");

String WelltodoEstate_nioroutes=("A4, B5");

String CBD_ioroutes=("A3");

String CBD_nioroutes=("A4, B5");

String Hospital_ioroutes=("B4");

String Hospital_nioroutes=("A1");

String GrungyNeighborhood_ioroutes=("A2, B1");

String MiddleClassSuburbs_ioroutes=("A1; B3");

String PoliceStation_ioroutes= ("R6");

String PoliceStation_nioroutes=("B1");

String FireStation_ioroutes=("B2, R5");

String FireStation_nioroutes=("A2");

String OldMarket_ioroutes=("R4");

String OldMarket_nioroutes=("B3");

String Mall_ioroutes=("R3");

String Mall_nioroutes=("B4");

}

publicstaticvoid main (String[] args)throws IOException{

System.out.println("Welcome to the Routefinder.");

System.out.println("Destination and Departure points include :");

System.out.println("Airport");

System.out.println("Church");

System.out.println("Well-to-do Estate");

System.out.println("CBD");

System.out.println("Hospital");

System.out.println("Grungy Neighborhood");

System.out.println("Middle-class Suburbs");

System.out.println("Police Station");

System.out.println("Fire Station");

System.out.println("Old Market");

System.out.println("Mall");

System.out.println("Please enter your Departure(From)");

String From = stdin.readLine();

if(From.equals(Places[0]))

System.out.println("Please enter your Destination(To)");

String To = stdin.readLine();

if(To.equals(Places[1]))

System.out.println("Thank you.");

}

}

There is an error 'cannot find symbol : variable Places)

on lines if(From.equals(Places[0]))

andif(To.equals(Places[1]))

Why?

[4669 byte] By [arro253a] at [2007-10-2 17:15:26]
# 1
Hi, please use the Java Naming Conventions (start with lower case letters for variables).Your problem is down to Scope. Places is defined in the init block, as such when you leave the init block, the variable "places" goes.
mlka at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 2
Thanks, I figured it was scope. So does that mean I should take out the } before public static void main ... ? When I do that, it says illegal start of expression on that line.
arro253a at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 3
No, that would move the method into the init block. You want to move the Places definition to before the init block.
mlka at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 4
You are then going to have a new problem. the init block runs when a new object is created, but you are using them in the static method "main".
mlka at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 5
Ok, I'm sorry to sound ignorant, but can you tell me what's the init block exactly ?
arro253a at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 6

The block of code thats is not in a method.

class T {

{ This is the init block

}

}

The fact that you asked suggests you should not be using it. Why is the code there, and not just in the main method.

<hides from rene/>

mlka at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 7
> Ok, I'm sorry to sound ignorant, but can you tell me> what's the init block exactly ?[url] http://java.sun.com/docs/books/tutorial/java/javaOO/initial.html[/url]
da.futta at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...
# 8
OK, I managed to fix it. I'm sure I'll have other questions later on for this stupid project, but anyway, thanks ....
arro253a at 2007-7-13 18:30:55 > top of Java-index,Java Essentials,Java Programming...