Java Reference
In-Depth Information
eXerCISeS 1
1.
a survey of 10 pop artists is made. each person votes for an artist by specifying the number
of the artist (a value from 1 to 10). each voter is allowed one vote for the artist of their choice.
the vote is recorded as a number from 1 to 10 . 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 10 is
a spoiled vote. a file, votes.txt , contains the names of the candidates. the first name is
considered as candidate 1, the second as candidate 2, and so on. the names are followed by
the votes. Write a program to read the data and evaluate the results of the survey.
print the results in alphabetical order by artist name and in order by votes received (most votes first).
print all output to the file, results.txt .
2.
Write a program to read names and phone numbers into two arrays. request a name and
print the person's phone number. Use binary search to look up the name.
3.
Write a program to read english words and their equivalent Spanish words into two arrays.
request the user to type several english words. For each, print the equivalent Spanish word.
Choose a suitable end-of-data marker. Search for the typed words using binary search.
Modify the program so that the user types Spanish words instead.
4.
the median of a set of n numbers (not necessarily distinct) is obtained by arranging the
numbers in order and taking the number in the middle. if n is odd, there is a unique middle
number. if n is even, then the average of the two middle values is the median. Write a
program to read a set of n positive integers (assume n < 100) and print their median; n is not
given, but 0 indicates the end of the data.
5.
the mode of a set of n numbers is the number that appears most frequently. For example, the
mode of 7 3 8 5 7 3 1 3 4 8 9 is 3 . Write a program to read a set of n positive integers
(assume n < 100) and print their mode; n is not given, but 0 indicates the end of the data.
6.
an array chosen contains n distinct integers arranged in no particular order. another array
called winners contains m distinct integers arranged in ascending order. Write code to
determine how many of the numbers in chosen appear in winners .
7.
a multiple-choice examination consists of 20 questions. each question has five choices,
labeled a, B, C, d, and e. the first line of data contains the correct answers to the 20
questions in the first 20 consecutive character positions, for example:
BeCdCBaadeBaCBaeddBe
each subsequent line contains the answers for a candidate. data on a line consists of a
candidate number (an integer), followed by one or more spaces, followed by the 20 answers
given by the candidate in the next 20 consecutive character positions. an X is used if a
candidate did not answer a particular question. You may assume all data is valid and stored
in a file exam.dat . a sample line is as follows:
4325 BeCdCBaXdeBaCCaedXBe
there are at most 100 candidates. a line containing a “candidate number” 0 only indicates
the end of the data.
Search WWH ::




Custom Search