Java Reference
In-Depth Information
Strive not to be a success, but rather to be of value.
Whatever the mind can conceive and believe, it can achieve.
There is only one way to avoid criticism: do nothing, say nothing,
and be nothing.
When run, Program P2.4 stores its output in the file output.txt . Here is the output:
Words Frequency
a 1
achieve 1
and 2
avoid 1
be 3
believe 1
but 1
can 2
conceive 1
criticism 1
do 1
is 1
it 1
mind 1
not 1
nothing 3
of 1
one 1
only 1
rather 1
say 1
strive 1
success 1
the 1
there 1
to 3
value 1
way 1
whatever 1
2.15 How to Return More Than One Value: Voting
This example will be used to illustrate several issues concerning the use of classes and objects. We will again use a
class to group data, and we will show how a function can return more than one value using an object.
Problem : In an election, there are seven candidates. Each voter is allowed one vote for the
candidate of their choice. The vote is recorded as a number from 1 to 7 . The number of voters
is unknown beforehand, but the votes are terminated by a vote of 0 . Any vote that is not a
number from 1 to 7 is an invalid (spoiled) vote.
 
Search WWH ::




Custom Search