Java Reference
In-Depth Information
Introduction
Thus far in this topic, Java programming examples have included code
statements that execute sequentially, from top to bottom, without skipping any
code, repeating any code, or branching to another class or method. Realistically,
most programs use a selection structure , also called an if…else structure , to
branch to a certain section of code and a repetition structure to repeat a certain
section of code. Both selection structures and repetition structures are consid-
ered to be control structures, because the logic of these structures controls the
order in which code statements execute. These structures will be covered in
detail later in the chapter as you learn how to write code that uses if…else state-
ments, while statements, and switch statements.
You also will learn how to write user-defined methods in Java in order to
break tasks into small sections of code that can be reused. You will learn how to
write a try statement and a catch statement to handle exceptions, in addition to
learning ways to test for validity, reasonableness, and accurate input. Finally, you
will learn how to write code to add check boxes and option buttons to an applet.
Chapter Four — Sales Commission
The programs developed in this chapter create a Commission program that
GetOuttaTown Travel, a nationwide travel agency, can use to calculate sales com-
mission for their travel agents. The agents at GetOuttaTown Travel can complete
three types of sales — telephone, in-store, and outside — each of which earns a
different commission percentage. The travel agency requires a computer pro-
gram that will accept a sales amount and then, based on a choice of commission
codes, will calculate a dollar commission amount using the formula, commission
= sales amount * commission rate. The commission code identifies the type of
sale and commission rate. Telephone sales receive a 10% commission, in-store
sales receive a 14% commission, and outside sales receive an 18% commission.
Output will include a formatted message displaying the calculated commission.
Two versions of the Commission program are developed in this chapter, as
shown in Figure 4-1. First, the Commission program is developed as an applica-
tion with two dialog boxes that provide text boxes for user input. Next, the
Commission program is developed as an applet that uses a text box and option
buttons for user input.
Search WWH ::




Custom Search