Introduction to Java using NetBeans

Section 5 : Decisions, Decisions


If ... Else ... Else if
A review!!!!


Include Reset Buttons on all Projects in this section.


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

Comparing Strings

Equal - if (strString1.equals(strString2))


Not Equal- if (!strString1.equals(strString2))


Example Icon Example1 - Integer Variables

Example Icon Example 2 - Boolean Variables


Example Icon Example 3 - String Variables

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. (Note: This is each item, not the total of the bill)

You should have at least 5 items available.

Create an application that asks the user for the amount/name of each item purchased and then returns the discounted price of each item and the total price of all items purchased.

Make sure that your output is formatted appropriately and that the form is user friendly

This image shows a Store Sale Advertisement.

No Above and Beyond Required