Java Reference
In-Depth Information
11.
Notice that the following, while correct, is not as easy to understand as the for-
each loop.
for ( int i; i < a.size(); i++)
System.out.println(a.get(i) + " differs from average by "
+ (a.get(i) average));
12. public static <T> int getMidindex(T[] a)
{
return a.length/2;
}
13.
This is a trick question. As we explained in the text, you cannot have an array of
type UnorderedPair<String>[] or of type Pair<String>[] .
Programming Projects
Many of these Programming Projects can be solved using AW's CodeMate.
To access these please go to: www.aw-bc.com/codemate .
1.
In the sport of diving, seven judges award a score between 0 and 10, where each
score may be a floating-point value. The highest and lowest scores are thrown
out and the remaining scores are added together. The sum is then multiplied by
the degree of difficulty for that dive. The degree of difficulty ranges from 1.2 to
3.8 points. The total is then multiplied by 0.6 to determine the diver's score.
Write a computer program that inputs a degree of difficulty and seven judges'
scores and outputs the overall score for that dive. The program should use an
ArrayList of type Double to store the scores.
2.
Write a program that uses an ArrayList of parameter type Contact to store a
database of contacts. The Contact class should store the contact's first and last
name, phone number, and email address. Add appropriate accessor and mutator
methods. Your database program should present a menu that allows the user to
add a contact, display all contacts, search for a specific contact and display it, or
search for a specific contact and give the user the option to delete it. The searches
should find any contact where any member variable contains a target search
string. For example, if “elmore” is the search target then any contact where the
first name, last name, phone number, or email address contains “elmore” should
be returned for display or deletion. Use the “for each” loop to iterate through the
ArrayList .
3.
Many Global Positioning Satellite (GPS) units can record waypoints. The way-
point marks the coordinates of a location on a map along with a timestamp.
Consider a GPS unit that stores waypoints in terms of an (X,Y) coordinate on a
map together with a timestamp t that records the number of seconds that have
Search WWH ::




Custom Search