0

i make a small program in java about Metro Station in Egypt so i specified the lines the passeger take a metro from it and the line they go to by boolean in default at classes boolean value is false but i want to make 4 variable changing in Main

this code specify the index of the stations in line 1 and make source1 true in the same time it works if i write it inline but when i write it in function always source1 is false as defualt and i can solve it please help

public void Searchinline1(String []line1,String sourceStation,String destinationStation,boolean source1,boolean destination1,int sourceindex,int destinationindex) {

    for (int i = 0; i < line1.length; i++) {
        if (sourceStation.equalsIgnoreCase(line1[i])) {
            source1=true;
            sourceindex=i;
        }
        if (destinationStation.equalsIgnoreCase(line1[i])) {
            destination1=true;
            destinationindex=i;
        }
    }

}

1 Answers1

0

Declare variables in your class and use this to change it's value.
this.source1 = true;

According to oracle

Within an instance method or a constructor, this is a reference to the current object — the object whose method or constructor is being called.

You can read official doc for this keyword http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html

Azak
  • 270
  • 1
  • 5
  • 15