2012-04-03 66 views
1

最初のネストされたif文で型エラーの不正な開始が発生しました。同様の質問がありましたが、これは通常、間違った中括弧が原因ですが、私は見えません。誰でも助けてくれますか?Java不正な型エラーの開始

public class Journey 
{ 
    private int date; 
    private double time; 
    private int busNumber; 
    private int journeyType; 
    public static double dayCharge; 
    public static final double maxDayCharge = 3.50; 
    public static double weekCharge; 
    public static final double maxWeekCharge = 15; 
    public static double monthCharge; 
    public static final double maxMonthCharge = 48; 
    private int journeyId; 
    private static int numberOfJourneys; 
    private double costOfJourney; 

    public int getDate(){ 
     return date; 
    } 
    public Double getTime(){ 
     return time; 
    } 
    public int getBusNumber(){ 
     return busNumber; 
    } 
    public double journeyCost(journey reqJourney){ 
     if (journeyType = 1){      //this is where the error occurs 
      if (dayCharge =< 2.50) 
      { 
       costOfJourney = 1; 
      } 
      else 
      { 
       costOfJourney = maxDayCharge-dayCharge; 
      } 

     } 
     else if (journeyType = 2) 
     { 
      if (dayCharge =< 1.80) 
      { 
       costOfJourney = 1.70; 
      } 
      else 
      { 
       costOfJourney = maxDayCharge-dayCharge; 
      } 
     } 
     else if (journeyType = 3) 
     { 
      if (dayCharge =< 1.60) 
      { 
       costOfJourney = 1.90; 
      } 
      else 
      { 
       costOfJourney = maxDayCharge-dayCharge; 
      } 

     }   
     return costOfJourney;  
    } 
    public boolean isInSequence(journey reqJourney){ 
     journey prevJourney = jArray.get(jArray.size()-1); 
     if (prevJourney.date > reqJourney.date) 
     { 
      return false; 
     } 

    } 
} 

答えて

1

等価性をテストするには、==を使用する必要があります。 =は代入演算子です。

オラクル社は、Javaオペレータを説明する良いtutorial docsを持っています。

また、Object.equals()==の間には重要な違いがあります。詳細については、this oneなどのその他のスタックオーバーフローの質問で詳しく説明しています。しかし、あなたがやっているようなプリミティブ型を比較す​​ると、==があなたの望むものです。

+0

多くのありがとうございます。 – seanysull

1

は次のようになります。もし、ブロック内

if (journeyType == 1){ 

発現は常に(真(または)偽のいずれか)ブール値になりべきです。

関連する問題