assignment 08.doc

advertisement
Java I CS 142 Week 09 Assignment
Given: A specialized class of trapezoids.
Mission Statement:
Derive characteristics of trapezoid “T”, by determining various Euclidean geometry
values about the trapezoid, including characteristics of two object classes
contained within “T”.
Input discussion & orientation:
1) “Screen Coordinate System” (SCS), as in your monitor. In the SCS the
upper left hand corner is the point (0,0).
The x-axis values increase from 0 “left to right”, thus the “upper right hand”
corner of the SC System is (Xmax,0).
The y-axis values increase from 0 “down to the “bottom” of your monitor,
making the lower left hand corner (0,Ymax).
Thus the diagonal corner from (0,0) = (Xmax , Ymax), otherwise known as the
“lower right-hand” corner.
In our Assignment, let Xmax = Ymax = 425, so your input bounds will lie in the
interval (0…425) allowing the Trapezoids to be displayed (for extra credit)
easily using the graphics2D API.
2) For the purposes of our assignment, a Trapezoid “T” will be defined as
4 points, labeled A, B, C, and D. Thus each trapezoid input is a single line
of 4 ordered-pairs, as in
A = (Xa, Ya)
B = (Xb, Yb)
C= (Xc, Yc)
D = (Xd, Yd)
2) All trapezoids provided as input in the sample input file “wk08_test.csv” will
have exactly one pair of parallel sides, the exclusive definition. These
parallel sides will be referred to in our discussion as line segments AB and
CD. The adjacent sides will be referred to as AD and BC. The magnitude of
theses line segments will be defined as:
a = magnitude of line segment (ls) CD = distance between (Xc,Yc) and (Xd,Yd)
b = magnitude of ls AB = distance between (Xa,Ya) and (Xb,Yb). Similarly
c = magnitude of ls AD = distance between (Xa,Ya) and (Xd,Yd).
d = magnitude of ls BC = distance between (Xb,Yb) and (Xc,Yc).
The magnitude of the ls orthogonal to AB and CD is defined as h, or “height”
For example, let
A = (10,20); B = (40,20); C = (30,10) and D = (15,10). The resultant trapezoid “T”
would be illustrated by Figure 1.
A complete discussion of Trapezoids can be found in the Wikipedia, the free
encyclopedia by following the link http://www.en.wikipedia.org/wiki/Trapezoid
4) Each Trapezoid “T” will contain two classes:
RightTriangles (RT) and Rectangles (R).
In our specialized case, T will contain at most 2 right triangles (RT1 and RT2), and
exactly one Rectangle (R). Your mission statement is to accept “T” as input, and
derive the values associated with T, including characteristics of the associated
objects RightTriangles (RT1 and RT2) and Rectangle R.
5) Code “snippets” will be provided & posted for this assignment. Specifically:
- snippet to open, read and parse the trapezoid T defined in the input file
- snippet method project() to “project” a point a desired distance using it’s
vector components to derive (find) a new point along the line.
The project() method will be used to determine the (x,y) coordinates of two
trapezoid points E and F. These points complete the definition of the right
triangles (RT1 and RT2) and rectangle “R” contained in the trapezoid T.
- snippet to open and write the derived characterisitcs & values associated
with T, RT1 and RT2 and R.
In our example, the rectangle “R” contained in “T” would be defined as:
R = the line segments DC, DE, CF and EF.
Similarly, the right triangles RT1 and RT2 contained in “T” would be defined a:
RT1 = the line segements AD, AE, and DE
RT2 = the line segements BC, BF, and CF
See Figure 2 for an illustration.
6) Program Requirements:
Each of the three classes Trapezoid, RightTriangle and Rectangle will have the
following:
- toString() method formatting information “nicely”
- equals() method, based on area comparison between similar types
- getArea() method
- setters & getters for the fields
Rectangle class has:
a. Fields:
- double width, height, area
b. Constructors:
- a no-arg constructor that makes a rectangle width=5.0, height=8.0
- a two-arg constructor that has (double width, double height) & calculates
area
RightTriangle class has:
a. Fields
- double fields base, height, area
b. Constructors:
- a no-arg constructor that makes a right-triangle base=2.5, height=8.0
- a two-arg constructor that has (double base, double height) & calculates
area
Trapezoid class has:
a. Fields
- double Xa,Ya, Xb,Yb, Xc, Yc, Xd, Yd
- a Rectangle
- a “list” (possibly empty !) of RightTriangles
Extra Credit Opportunities:
a) Display your trapezoid & derived right-triangle(s) & rectangle using
graphics2D API
b) In output file, use toString() methods to describe the trapezoid input, and the
values for the derived Euclidean shapes (points E, F, etc.)
Due: 90 minutes after class starts on Thursday, March 14th
Download