Java Reference
In-Depth Information
1. As an example of array list usefulness, create a JavaQuiz application
thatpresentsamultiple-choice-basedquizonJavafeatures.The JavaQuiz
class's main() method first populates the array list with the entries in
a QuizEntry array (e.g., new QuizEntry("what was java's
original name?", new String[] { "Oak", "Duke", "J",
"None of the above" },'a') ). Each entry consists of a ques-
swer. main() thenusesthearraylist's iterator() methodtoreturnan
Iterator instance, and this instance's hasNext() and next() meth-
ods to iterate over the list. Each of the iterations outputs the question and
AftertheuserentersA,B,C,orD(via ), main()
outputs a message stating whether or not the user made the correct choice.
2. Createaword-countingapplication( WC )thatreadswordsfromthestandard
input (via ) and stores them in a map along with
the java.lang.Character class's isLetter() methodtomakethis
determination. Also, use Map 's get() and put() methods and take ad-
vantage of autoboxing to record a new entry or update an existing entry's
count—the first time a word is seen, its count is set to 1. Use Map 's
entrySet() method to return a Set of entries, and iterate over these
entries, outputting each entry to the standard output.
3. Collections provides the static int fre-
quency(Collection<?> c, Object o) methodtoreturnthenum-
berofcollection c elementsthatareequalto o .Createa FrequencyDemo
except for the last argument in a list, and then calls frequency() with
outputs this method's return value (the number of occurrences of the last
ample, java FrequencyDemo should output Number of occur-
rences of null = 0 , and java FrequencyDemo how much
wood could a woodchuck chuck if a woodchuck could
chuck wood wood should output Number of occurrences of
wood = 2 .
Search WWH ::

Custom Search