non static variable cannot be referenced...error.. on a timetable
Hey Guys, I have written a program which will search through
information (a bus timetable) and return whether a journey is
available. i have a problem on the three last paragraphs which should
allow users to enter time, etc.. the error i get on all three is non
static variable 'buses' cannot be referenced from a static context...
HERE is the Code:non static variable cannot be referenced
import java.io.*;
import java.util.*;
class EasyInSlightlyImproved {
static InputStreamReader is = new InputStreamReader( System.in );
static BufferedReader br = new BufferedReader( is );
StringTokenizer st;
StringTokenizer getToken() throws IOException {
String s = br.readLine();
return new StringTokenizer(s);
}
String[] buses = { "Cardiff,9.25,Thornhill,9.50", "Cardiff,
9.55,Newport,10.20", "Thornhill,10.00,Llanishan,10.25"};
float readFloat() {
try {
st = getToken();
return new Float(st.nextToken()).floatValue();
} catch (Exception e) {
System.err.println("Exception in EasyIn.readFloat");
return 0.0F;
}
}
String readString() {
try {
return br.readLine();
} catch (IOException ioe) {
System.err.println("IO Exception in EasyIn.readString");
return "";
}
}
public static void main(String args[]) {
EasyInSlightlyImproved easy = new EasyInSlightlyImproved();
System.out.print("enter time of bus: ");
System.out.flush();
float time = easy.readFloat();
System.out.println("You entered: " + time);
for(String s : buses){
String[] row = s.split(",");
if (Float.valueOf(row[1]).compareTo(time)==0){
System.out.println("Fount time in Schedule");
}
}
System.out.print("enter point of departure: ");
System.out.flush();
String departure = easy.readString();
System.out.println("you entered: " + departure);
for (String s : buses){
String[] row = s.split(",");
if (row[0].compareToIgnoreCase(departure)==0);{
System.out.println("found departure in schedule");
}
}
System.out.print("enter destination: ");
System.out.flush();
String destination = easy.readString();
System.out.println("you entered: " + destination);
for (String s : buses) {
String[] row = s.split(",");
if (row[0].compareToIgnoreCase(destination)==0){
System.out.println("found destination in schedule");
}
}
}
}
Any Pointers Would Be Great - Cheers, I appreciate your time.
Paddy