please help me to sort my else if problem

please help me to sort out my if statement. Because, my if statement never ends. It goes on to the next else statement after completing the task of the if statement.

Below is the coding:

if ( Age<25)

{

price = inputBox.getDouble("Enter Destination Price");

subtotal = (tickets * price);

Total= price-(price *0.3);

studentDiscount = subtotal + Total;

}

Age = inputBox.getInteger("Enter Age(between 25 and 130):");

if(Age<50)

{

price = inputBox.getDouble("Enter Destination Price");

subtotal = (tickets * price) ;

Total= price-(price *0.5);

ElderlyDiscount = subtotal + Total;

}

[685 byte] By [leenash76a] at [2007-9-28 3:22:01]
# 1

You haven't put an else statement in there!

>

> if ( Age<25)

> // The code in brackets executes if Age is less than 25

> {

> price = inputBox.getDouble("Enter Destination

> Price");

> subtotal = (tickets * price);

> Total= price-(price *0.3);

> studentDiscount = subtotal + Total;

>

> }

> Age = inputBox.getInteger("Enter Age(between 25 and

> 130):"); // This line always executes

>

> if(Age<50) // The code in brackets executes if Age is less than 50

> {

> price = inputBox.getDouble("Enter Destination

> Price");

> subtotal = (tickets * price) ;

> Total= price-(price *0.5);

> ElderlyDiscount = subtotal + Total;

>

>

> }

>

if (booleanExpression) {

// code executes if expression evaluates to true

} else {

// code executes if expression evaluates to false

}

m_ridsdalea at 2007-7-7 22:54:36 > top of Java-index,Other Topics,Algorithms...
# 2

if ( Age<25) {

price = inputBox.getDouble("Enter Destination Price");

subtotal = (tickets * price);

Total= price-(price *0.3);

studentDiscount = subtotal + Total;

}

Age = inputBox.getInteger("Enter Age(between 25 and 130):");

if (Age<50) {

price = inputBox.getDouble("Enter Destination Price");

subtotal = (tickets * price) ;

Total= price-(price *0.5);

ElderlyDiscount = subtotal + Total;

}

i think you are trying to compute different prices based on the age of the passenger. try to merge this two statement to an if else

if (age < 25)

// student price

else

// elderly price

or

final int STUDENT_AGE_BRACKET = ; << Put the student bracket here

final int ELDERLY_AGE_BRACKET = ; << put the elderly bracket here

if (age <= STUDENT_AGE_BRACKET)

// student price

if (age >= ELDERLY_AGE_BRACKET)

// elderly price

joyceAnnNewToForuma at 2007-7-7 22:54:36 > top of Java-index,Other Topics,Algorithms...