1

I am getting an illegal start of type error at the first nested if statement, having looked at similar questions i understand this is usually caused by a misplaced brace, however, i cannot see one. Could anyone help?

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;
        }

    }
}
seanysull
  • 720
  • 1
  • 8
  • 24

2 Answers2

1

You need to use == to test equality. = is the assignment operator.

Oracle has good tutorial docs explaining Java operators.

On a related note, there's also an important distinction between Object.equals() and == which is covered in detail in other Stack Overflow questions like this one. However, when comparing primitive types like you're doing, == is what you want.

Community
  • 1
  • 1
ulmangt
  • 5,343
  • 3
  • 23
  • 36
1

Should be:

 if (journeyType == 1){  

Expression in if block should always results in boolean value (either true (or) false).

kosa
  • 65,990
  • 13
  • 130
  • 167