Java Reference
In-Depth Information
If the call is larger(5, 3) , for example, the first method executes because the
actual parameters match the formal parameters of
the first method. If
the call
is
larger('A', '9') , the second method executes, and so on.
Method overloading is used when you have the same action for different types of data.
Of course, for method overloading to work, you must give the definition of each method.
PROGRAMMING EXAMPLE: Data Comparison
Two groups of students at a local university are enrolled in special courses during the
summer semester. The courses are offered for the first time and are taught by different
teachers. At the end of the semester, both groups are given the same tests for the same
courses and their scores are recorded in separate files. The data in each file is in the
following form:
courseID
score1, score2, ..., scoreN -999
courseID
score1, score2, ..., scoreM -999
.
.
.
7
This programming example illustrates:
1. How to read data from more than one file in the same program.
2. How to send the output to a file.
3. How to generate bar graphs.
4. With the help of methods and parameter passing, how to use the
same program segment on different (but similar) sets of data.
5. How to use structured design to solve a problem and how to per-
form parameter passing.
This program is broken into two parts. First, you learn how to read data from more
than one file. Second, you learn how to generate bar graphs.
Next we write a program that finds the average course score for each course for each
group. The output is of the following form:
Course ID
Group No
Course Average
CSC
1
83.71
2
80.82
ENG
1
82.00
2
78.20
.
.
.
Avg for group 1: 82.04
Avg for group 2: 82.01
Search WWH ::




Custom Search