Java Conditions

All tutorials are implemented in text (here), and also with exercises and multimedia in the Tutorial Player. The main home page has a search engines, and more facilities.

if
Tenary Operator
Switch

if

Brackets are used and operators:

if (thisBalance > 20000) {
goodCustomer = true;
} else {
goodCustomer = false;
}

Tenary Operator

The tenary operator can also be used,

condition ? trueResult actions :falseResult actions

For example

goodCustomer ? customerMarketing.offerCustomer(thisCustomer) : customerMarketing.freezeCustomer(thisCustomer);

The class Marketing has methods offerCustomer and freezeCustomer implemented. These would offer a good customer more products, and for a bad one, offers would be frozen.

Switch

The switch statement simplifies a complicated if statement:

switch (customerOption) {
case '1':
Stocks.buy(thisCustomer);
break;
case '2':
Stocks.sell(thisCustomer);
break;
}