Hi guys,
I am having an issue with some Java that I have written.
I have a class called Journey and within this class I have some methods. In my code I have a boolean data member set as false by default. Then in a method I change the value of the data member to true if the criteria of an if statement is met.
When I test the code it seems as if the boolean value doesn't get changed to true if the if statement criteria is met which means the boolean value remains as false.
Any ideas regarding what I am doing wrong?
Data members
private int year = 0; private int month = 0; private int day = 0; private int lastDayOfMonth = 0; private boolean discount = false;
Methods
public void lastDay() { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); GregorianCalendar date = new GregorianCalendar( year, month, day ); lastDayOfMonth = date.getActualMaximum(GregorianCalendar.DAY_OF_MONTH); if (day == lastDayOfMonth) discount = true; }
public double getPrice() { if (discount == true) return journeyPrices[departing][destination] * 100; else return journeyPrices[departing][destination]; }