Java Reference
In-Depth Information
The getComm() Method
In the Commission program, a method named getComm() will get a
commission rate based on the dollar amount of the sales and the employee sales
code. Figure 4-27 displays the line of code to call the getComm() method
(line 24) and the getComm() method definition (lines 82 through 104).
24
answer = getComm ( dollars,empCode ) ;
82
83
//The getComm() method accepts the dollars and code and returns the commission.
84
public static double getComm ( double employeeSales, int employeeCode )
85
{
86
double commission = 0.0;
87
88
switch ( employeeCode )
89
{
90
case 1:
91
commission = .10 * employeeSales;
92
break ;
93
94
case 2:
95
commission = .14 * employeeSales;
96
break ;
97
98
case 3:
99
commission = .18 * employeeSales;
100
break ;
101
}
102
return commission;
103
}
104
FIGURE 4-27
When the getComm() method is called from the main() method in line 24,
it sends the arguments, dollars and empCode, to the getComm() method itself.
The method returns a double value that is stored in a variable named answer.
The method header for the getComm() method displays in line 84. Its two
parameters are declared to accept the values sent from the calling statement.
Those values do not have to have different names than the arguments, dollars
and empCode, used in line 24; however, because Java considers them different
storage locations, visible only in their respective methods, most programmers
assign the arguments and parameters different — but user-friendly and
related — names. The arguments, dollars and empCode, become the parameters,
employeeSales and employeeCode, in the getComm() method.
Search WWH ::




Custom Search