Reference no: EM132198042
Write an error-free Java program to do the following things. The program is modeled on a simple game where shapes move around the screen and if they overlap, then one of them gets "swallowed". In this case, the triangle shape swallows any circle that comes close to its center.
Use a Shape2D class that has only private data members. The data members should be floating point (decimal) numbers that represent the (x, y) coordinates of the center of the shape as well as at least one data member that corresponds to size of the object.
There should be a Circle class that inherits from Shape2D and a Triangle class that inherits from Shape2D. In general, put whatever methods/data that can be used by all (2D) shapes in the superclass and put Triangle/Circle specific methods/data into the subclass.
The main program should have three circle objects and one triangle. The circles start with radius = 1 and location at origin. The triangle starts with base of 2 and a height of 3.5 (use a constructor).
Input from the user a (new) radius for each circle. The radii will correspond to small, med, large circles. Input from the user a location of the triangle. Set the data members (instance variables) of the circles and triangle based on the user input.
To simulate the game, we would move the circles over time and determine if they intersect the triangle. For this program, move the small circle left by .75, move the medium circle up by 1.3 and move the large circle at a -45 degree angle a distance of .7071 from the origin.
Determine if any of the circles overlap the triangle. We will define overlap as the positions of the objects are within 0.5 of each other. If one or more circles overlap the triangle, make the triangle better by increasing the base and height of the triangle by a scale factor equal to the area of the circle. For example, if the area of the circle is 2.5 then the base and height of the triangle are multiplied by 2.5. The radius of the overlapping circle should be set to 0 and its location set to the origin.
Override the toString method to display the area and location of all of the shapes. That is, System.out.println(object) to display the data about the object.