Java Reference
In-Depth Information
The getSales() method displays an input dialog box and prompts the user for
a sales amount in dollars. If the user clicks the Cancel button or Close button in
the user interface, the program will terminate. If not, the getSales() method will
make sure the value entered is greater than zero. If the value is not greater than
zero, the program will display an error message and allow the user to enter a new
value. When a valid value for sales amount is entered, the code returns the value
to the main() method for storage.
The getCode() method then displays a list of valid commission codes that
the user can enter. The getCode() method also checks for a valid integer between
1 and 3. If an invalid number is entered, the method displays an error message
and prompts the user to enter a new value. When a valid value for commission
code is entered, the code value is returned to the main() method for storage.
The getComm() method uses the two previous input values to calculate a
commission amount using the formula commission = sales amount * commis-
sion rate, and then returns it to the main() method for storage.
The output() method displays formatted output with dollar signs, commas,
and decimal points. The output message will include the sales amount and the
total commission.
The finish() method calls the System.exit() method to close all dialog boxes
and then terminate the program.
VALIDATE DESIGN Once you have designed the program, you can validate
the design by stepping through the requirements document and making sure
that the design addresses each requirement. If possible, you also should step
through the solution with test data to verify that the solution meets the require-
ments. The user also should review the design to confirm that it solves the prob-
lem outlined in the requirements. The user may realize that the instructions the
programmer was given do not cover all the company's needs, requiring addi-
tional features. By comparing the program design with the original require-
ments, both the programmer and the user can validate that the solution is
correct and satisfactory.
Having analyzed the problem, designed the interface, and designed the pro-
gram logic, the analysis and design of the application is complete. As shown in
Table 4-1 on page 219, the next task in the development cycle is to implement
the design by creating a new Java program using TextPad. Implementing the
design for this program involves creating Java methods to modularize the task of
obtaining a sales amount, using Java's ability to catch errors as they occur, and
then creating a module to display an appropriate error message. The program
code also involves using code statements that will allow the program to make
decisions based on user input.
Starting a New Java Program in TextPad
In Chapter 2, you learned how to start TextPad and save a file using a Java file
type. The steps on the next page start TextPad and save the TextPad document
using a Java file type.
Search WWH ::




Custom Search