Introduction to Java using NetBeans

Section 5 : Decisions, Decisions


The if..else Statement

The if..else statement is a conditional control structure which executes a block of code when a condition is true, or executes an alternative block of code when the condition is false.

Example Icon Example 1



Conditional Operators

The condition in an if statement is a Boolean expression which evaluates to either true or false.

Conditional operators can be used to form Boolean expressions.

Conditional Operator Meaning
== equal to
< less than
<= less than or equal to
> greater than
>= greater than or equal to
!= not equal


Example Icon Example 2


Tips icon Tips

If you do not want to execute an alternative block of code, you can use the if statement without the else statement.

if (numStudents > 25)
     System.out.println ("The number of students is greater than 25.");



Assignment 5.1 - Sale

Create a GUI for the Store Sale


During a special sale at a store, a 10% discount is taken off of items purchased that are over $50.00.

Create an application that prompts the user for the amount of each item purchased and then returns the discounted price of each item and the total price of all items purchased(You may use check boxes etc.)

Make sure that your output is formatted appropriately.

This image shows a Store Sale Advertisement.