Java Reference
In-Depth Information
Implement the Design — Phase 4
The implementation phase of the program development cycle involves
writing the code that translates the design into a program and, if needed, creat-
ing the user interface. Writing the code, or coding, also includes writing internal
documentation, or comments , which are notes within the code that explain the
purpose of the code. When programmers write the code and create the interface,
their job includes testing the code as they write it. Related code that performs a
specific task or function should be tested for correctness during the program-
ming process. This type of testing is known as unit testing .
Figure 1-16 shows some of the code necessary to implement the
getShipping() method for the Shipping Charge Calculator, based on the
flowchart in Figure 1-14 on page 18 and the pseudocode in Figure 1-15 on the
previous page.
1 // this method accepts an integer named ounces
2 // and returns a double named shipping
3 public static double getShipping ( int ounces )
4 {
5
double basicCharge;
6
double shipping;
7
8
// set the basic shipping charge to $12.95
9
basicCharge = 12.95;
10
11
// if the ounces are greater than 16 calculate the
12
// extra charge at 30 cents per extra ounce
13
if ( ounces > 16 )
14
shipping = basicCharge + (( ounces-16 ) * .3 ) ;
15
else
16
shipping = basicCharge;
17
18
return shipping;
19 }
FIGURE 1-16
Figure 1-17 shows the user interface developed for the GUI application from
the original storyboard design illustrated in Figure 1-12 on page 15.
Shipping Charge
Calculator application
window
input text
box
output
text box
buttons
FIGURE 1-17
Search WWH ::




Custom Search