Java Reference
In-Depth Information
Programming Projects
Visit www.myprogramminglab.com to complete select exercises online and get instant
feedback.
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 instance 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 waypoint
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 elapsed since the
unit was turned on. Write a program that allows the user to enter as many way-
points as desired, storing each waypoint in an ArrayList , where each waypoint is
represented by a class that you design. Each waypoint represents a successive sample
point during a hike along some route. The coordinates should be input as double s,
and the timestamp as an integer. Have your program compute the total distance
traveled and the average speed in miles per hour. Use the map scaling factor of
1 = 0.1 miles. For example, if the only two waypoints are (X = 1,Y = 1,T = 0) and
(X = 2,Y = 1,T = 3600), then the hiker traveled a distance of 0.1 miles in 3,600 sec-
onds, or 0.1 miles per hour.
4. Write a generic class, MyMathClass , with a type parameter T where T is a numeric
object type (e.g., Integer , Double , or any class that extends java.lang.Number ).
Add a method named standardDeviation that takes an ArrayList of type T and
returns as a double the standard deviation of the values in the ArrayList . Use the
doubleValue () method in the Number class to retrieve the value of each number
as a double. Refer to Programming Project 6.5 for a definition of computing the
standard deviation. Test your method with suitable data. Your program should
generate a compile-time error if your standard deviation method is invoked on an
ArrayList that is defined for nonnumeric elements (e.g., Strings ).
 
Search WWH ::




Custom Search