everything on the file
Microsoft Word - S21 - EECS 1510 Project 2 - GeometricFigures 030821 EECS 1510 – Introduction to Object-Oriented Programming in Java Spring 2021 – Programming Assignment 2 – Geometric Figures Due: April 4, 2021 @ 11:59 PM Define the abstract GeometricObject class that contains: An abstract method called contains that accepts doubles x and y An abstract method for calculating perimeter called getPerimeter() An abstract method for calculating area called getArea() Define the Triangle2D class that extends GeometricObject and contains: Three points named p1, p2, and p3 of the type MyPoint with getter and setter methods. MyPoint will be given to you in the workspace provided on Blackboard. A no-arg constructor that creates a default triangle with the points (0, 0), (1, 1), and (2, 5). A constructor that creates a triangle with the specified points. A method getArea() that returns the area of the triangle. A method getPerimeter() that returns the perimeter of the triangle. A method contains(MyPoint p) that returns true if the specified point p is inside this triangle (see Figure 10.22a). A method contains(Triangle2D t) that returns true if the specified triangle is inside this triangle (see Figure 10.22b). A method overlaps(Triangle2D t) that returns true if the specified triangle overlaps with this triangle (see Figure 10.22c). FIGURE 10.22 (a) A point is inside the triangle. (b) A triangle is inside another triangle. (c) A triangle overlaps another triangle. Write a test program that reads in a file MyTriangles.txt which will have the x, y coordinates for the 3 vertices of ten (10) different Triangles. You will then create each Triangle using Triangle2D constructor new Triangle2D(x1, y1, x2, y2, x3, y3), and then display the area and perimeter for each triangle. You will then use your contains method to determine if each triangle is contained inside the others (10.22b). You will check to see if each triangle overlaps the others using your overlaps method (10.22c). See Table 1 for output table. Finally, you will read in one more file MyPoints.txt which will have 100 coordinates. You will check all 100 coordinates and count how many of the 100 are in EACH triangle (10.22a). You will report the count and the percentage (See Table 1). (Hint: For the formula to compute the area of a triangle, see Programming Exercise 2.19. To detect whether a point is inside a triangle, draw three dashed lines, as shown in Figure 10.23. If the point is inside a triangle, each dashed line should intersect a side only once. If a dashed line intersects a side twice, then the point must be outside the triangle. For the algorithm of finding the intersecting point of two lines, see Programming Exercise 3.25.) FIGURE 10.23 (a) A point is inside the triangle. (b) A point is outside the triangle Next, create a class MyRectangle2D class that extends the GeometricObject class. My Rectangle2D should contain: Two double data fields named x and y that specify the center of the rectangle with getter and setter methods. (Assume that the rectangle sides are parallel to x- or y- axes.) The double data fields width and height with getter and setter methods. A no-arg constructor that creates a default rectangle with (0, 0) for (x, y) and 1 for both width and height. A constructor that creates a rectangle with the specified x, y, width, and height. A method getArea() that returns the area of the rectangle. A method getPerimeter() that returns the perimeter of the rectangle. A method contains(double x, double y) that returns true if the specified point (x, y) is inside this rectangle (see Figure 10.24a). A method contains(MyRectangle2D r) that returns true if the specified rectangle is inside this rectangle (see Figure 10.24b). A method overlaps(MyRectangle2D r) that returns true if the specified rectangle overlaps with this rectangle (see Figure 10.24c). FIGURE 10.24 A point is inside the rectangle. (b) A rectangle is inside another rectangle. (c) A rectangle overlaps another rectangle. (d) Points are enclosed inside a rectangle. Write a test program that reads in a file MyRectangles.txt which will have the x, y coordinates for the center as well as the width and height for several rectangles. You will then create each Rectangle using Rectangle2D constructor new Rectangle2D(x1, y1, height, width), and then display the area and perimeter for each rectangle. You will then use your contains method to determine if each triangle is contained inside the others (10.24b). Finally, you will check to see if each rectangle overlaps the others using your overlaps method (10.24c). Finally, you will read in one more file MyPoints.txt which will have 100 coordinates. You will check all 100 coordinates and count how many of the 100 are in EACH triangle (10.24a). You will report the count and the percentage. See Table 1 for output table (The code for the output table will be provided in the workspace on BB). TABLE 1 Your code should have an appropriate level of documentation. At a minimum: There should be a comment block (this can be either a block comment or multiple single-line comments) at the top of your class that introduces the program, provides the date, and your name. Identifiers should have descriptive names and follow the naming conventions we covered in class. When variables are defined, a brief description of their purpose is appropriate, unless the variable’s name itself makes it obvious what the variable is all about, or if the variable is “generic”, such as using i or j to iterate through a list. Opening / closing braces should be on a line by themselves (Allman style) unless there’s a good reason not to. Indentation should be either 3 or 4 characters. For more information on indentation styles, see http://en.wikipedia.org/wiki/Indent_style Submit your work to Blackboard by creating a 7-zip archive of your entire workspace. Your WORKSPACE must be called LastnameFirstnameProj2. This way, I can simply un-zip your submission, point Eclipse at it, and go straight to your project. Do NOT submit just a .java source file, and do NOT submit just the folder with your project! If you have been working on a lot of little “mini-projects” along the way, and your workspace is littered with other projects, you may want to create a new one for your “projects to turn in” as opposed to your “practice projects” – you can have multiple workspaces on your flash drive. The workspace you submit MUST match the workspace that was given to you on Blackboard. Your zip file should be the same as your name, last-name-first, as in “Smith, Bob.7z”. If you don’t have 7-zip, you can get it at http://www.7-zip.org. If you can’t run 7-zip (i.e., you’re not on a Windows machine), a .zip file is acceptable, but 7-zip is strongly preferred. Files compressed with bzip2, gzip, RAR, or any other compressor will not be accepted. PLEDGE: By signing below, I confirm that the work I am submitting is my own. I did not work with any other person or group from this class. I did not work with anyone that has previously taken this class unless approved by my instructor. I did not copy code from the internet. I did not copy code from my textbook without making appropriate citation. I did not receive help from any outside person. I confirm that I used my text book and the lecture slides only. I further confirm that I did not witness any of my classmates giving or receiving help as outlined above. In summary: No Aid Given, Received, nor Observed: Signed: ___________________________ DATE: _________________________________