Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram does what is inside every if-statement in the method. Not supposed to
    primarykey
    data
    text
    <p>I have a program which I am writing which in one particular case enters every if-statement. But it isn't supposed to. I govern whether or not it should do just that by a boolean value which i send with the reference to the method. But it still won't work properly.</p> <p>Here is the code snippet of the two methods included:</p> <pre><code> void tilStasjon(String startStasjon){ boolean sjekkStasjon=true; while(sjekkStasjon){ System.out.println("Vennligst tast inn til-stasjonen: "); String sluttStasjon=input.next().toLowerCase(); if(stasjonerMap.containsKey(sluttStasjon)){ if(sluttStasjon!="ringen"){ sjekkStasjon=false; beregnRuter(startStasjon, sluttStasjon); } }else{ System.out.println("Stasjon ikke funnet."); sjekkStasjon=true; } } } void beregnRuter(String startStasjon, String sluttStasjon){ Stasjon til=stasjonerMap.get(startStasjon); Stasjon fra=stasjonerMap.get(sluttStasjon); ArrayList&lt;Linje&gt; fraLinjeListe=new ArrayList&lt;Linje&gt;(fra.linjeList); ArrayList&lt;Linje&gt; tilLinjeListe=new ArrayList&lt;Linje&gt;(til.linjeList); int tilStasjonsNummer, fraStasjonsNummer; int retning; double tid= 0.0; String endeStasjonsNavn; boolean overgang=false; tilStasjonsNummer=0; fraStasjonsNummer=0; for (int i = 0; i &lt; fraLinjeListe.size(); i++) { for (int j = 0; j &lt; tilLinjeListe.size(); j++) { if(fra.linjeList.get(i).equals(til.linjeList.get(j))){ System.out.println(fra.linjeList.get(i).linjeNummer); Linje aktuellLinje=linjerMap.get(fra.linjeList.get(i).linjeNummer); tilStasjonsNummer=aktuellLinje.stasjonsNummer(til); fraStasjonsNummer=aktuellLinje.stasjonsNummer(fra); retning=tilStasjonsNummer-fraStasjonsNummer; tid=beregnTid(retning, overgang, aktuellLinje); endeStasjonsNavn=aktuellLinje.endestasjon(retning); System.out.println("Ta T-bane linje " + aktuellLinje.linjeNummer + " fra " + startStasjon + " til " + sluttStasjon + " i retning " + endeStasjonsNavn + ". Estimert reisetid: " + tid); } } } } </code></pre> <p>Below here is the method where the problem occurs. It enters both the outer if and else-if. Why is that?</p> <pre><code> double beregnTid(int retning, boolean overgang, Linje aktuellLinje){ double tidMellomStasjoner; double tid=0.0; int absRetning=Math.abs(retning); double tidOvergang; if(overgang=false){ if(aktuellLinje.type==0){ System.out.println(absRetning); tidMellomStasjoner=1.8; tid=tidMellomStasjoner*absRetning; }else if(aktuellLinje.type==1){ tidMellomStasjoner=1.4; tid=tidMellomStasjoner*absRetning; } }else if(overgang=true){ if(aktuellLinje.type==0){ System.out.println("Test"); tidOvergang=7.5; tidMellomStasjoner=1.8; tid=(tidMellomStasjoner*absRetning)+tidOvergang; }else if(aktuellLinje.type==1){ tidOvergang=5.0; tidMellomStasjoner=1.4; tid=(tidMellomStasjoner*absRetning)+tidOvergang; } } return tid; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload