Documente Academic
Documente Profesional
Documente Cultură
109 is the ID of the osprey. 58734 is the easting (x) coordinate. 24387 is the northing (y)
coordinate.
Sighting.java
An instance of this class is used to represent each osprey sighting. This class has two data
fieldsone for easting and one for northing. Write a constructor that takes in two
arguments and sets the value for the two data fields. Implement the following three
methods in this class:
public void print() //prints the coordinates
public static double distance(Sighting p1, Sighting p2)
//calculate the distance between position p1 and position p2.
public static double area(Sighting A, Sighting B, Sighting C)
//calculates the area of the triangle with vertices A, B, and C
At the end, write a main() method in this class to test if your area function gives the right
output. Use the following co-ordinates for A, B and C.
Co-ordinate Easting Northing
A 100 100
B 100 200
C 200 100
Osprey.java
An instance of this class is used to represent an osprey. This class should have two data
fields. One is the ID number of the osprey and the other is a linked list of sightings.
Please use the SLinkedList presented in class as the linked list. Write a constructor for
this class. Depending on your preference, you could take in one argument or multiple
arguments. Provide get methods for both data fields.
PS8Main.java
In main(), read in data from data.txt, and create a linked list of ospreys. (Again, use the
SLinkedList presented in class.)
After you have read in all the data and put them in the linked lists, go through the linked
list and print out the id number and list of sightings and the foraging area for each osprey.
Triangle:
Area = 0.5bc sin A c b
b2 + c2 a2
cos A =
2bc
therefore B C
a
b2 + c2 a2
Area = 0.5bc sin arccos
2bc
Extra Credit(15%)
Let us assume that the sightings for each Osprey are randomly recorded, i.e., the vertices
are not recorded in counter clockwise fashion. Change your code such that you will still
be able to calculate the correct foraging area for each Osprey.
Turnin
Turnin Requirements
Hardcopy and electronic copy of ALL source code (all .java files). Remember to
comment your code, points will be taken off for insufficient comments.
Place a comment with your name, username, section, TA's name, assignment number,
and list of people with whom you have discussed the problem set on ALL files you
submit.
Electronic Turnin
Use SecureFX (or another secure ftp or secure shell program) to upload your problem set
to your 1.00 homework locker.
Detailed instructions of how to upload are on the course website.
Since your problem set is due at the beginning of lecture, your uploaded problem should
have a timestamp of no later than morning on the due date.
Penalties
Missing Hardcopy: -10% off problem score if missing hardcopy.
Missing Electronic Copy: -30% off problem score if missing electronic copy.
Late Turnin: -30% off problem score if 1 day late. More than 1 day late = NO
CREDIT.
If your problem set is late, or if a professor has granted you an extension in advance, do
not submit a printed copy of your problem set.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the United States and other
countries.