Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part I. Defining and Implementing Shape Classes (60 points) You should design classes for three different shapes (triangle, square, and circle) with the specifications listed

Part I. Defining and Implementing Shape Classes (60 points) You should design classes for three different shapes (triangle, square, and circle) with the specifications listed below. These classes are to be used by the main program (the class with the main method), and passed to the Canvas class for drawing. Thus, they must use standard class names and method names in order to work correctly. The jUnit tests we will provide you with will also require standardized names, so if your tests pass, then your names are satisfactory. Circle class Methods: Name: Circle (constructor); input: x position (double), y position (double), radius (double); output : object of type Circle Name: calculatePerimeter; input: none; output: perimeter of the circle (type double) Name: calculateArea; input: none; output: area of the circle (double) Name: setColor; input: color of the shape (type Color); output: none Name: setPos; input: x, y position of the center (both doubles) output: none Name: setRadius; input: radius (double) output: none Name: getColor; input: none; output: color of the shape (type Color); Name: getXPos; input: none; output: x position of the center (double) Name: getYPos; input: none; output: y position of the center (double) Name: getRadius; input: none; output: radius (double) Any data members needed to support these methods. Note: the Color class is implemented in the java.awt library, which you can use by including the following statement at the top of your class definition file: import java.awt.*; See the Java API documentation for more details on this class (note the static data fields, e.g. Color.BLUE). Triangle class Methods: Name: Triangle (constructor); input: x position of bottom left corner (double), y position of bottom left corner (double), width (double), height (double); output: object of type Triangle Name: calculatePerimeter; input: none; output: perimeter of the triangle (type double) Name: calculateArea; input: none; output: area of the triangle (double) Name: setColor; input: color of the shape (type Color); output: none Name: setPos; input: x, y position of bottom left corner (both doubles) output: none Name: setHeight; input: height (double) output: none Name: setWidth; input: width (double) output: none Name: getColor; input: none; output: color of the shape (type Color); Name: getXPos; input: none; output: x position of the bottom left corner (double) Name: getYPos; input: none; output: y position of the bottom left corner (double) Name: getHeight; input: none; output: height (double) Name: getWidth; input: none; output:width (double) Any data members needed to support these methods. HINT: You can assume the triangles we want to draw are isosceles triangles, i.e.: Rectangle class Name: Rectangle (constructor); input: x position of bottom left corner (double), y position of bottom left corner (double), width (double), height (double); output: object of type Rectangle Name: calculatePerimeter; input: none; output: perimeter of the rectangle (type double) Name: calculateArea; input: none; output: area of the rectangle (double) Name: setColor; input: color of the shape (type Color); output: none Name: setPos; input: x, y position of bottom left corner (both doubles) output: none Name: setHeight; input: height (double) output: none Name: setWidth; input: width (double) output: none Name: getColor; input: none; output: color of the shape (type Color); Name: getXPos; input: none; output: x position of the bottom left corner (double) Name: getYPos; input: none; output: y position of the bottom left corner (double) Name: getHeight; input: none; output: height (double) Name: getWidth; input: none; output: width (double) Any data members needed to support these methods. To verify your classes are implemented correctly, you should run the jUnit test classes, which we have provided for you. (x, y) W / 2 H Part II. Writing a program that draws a fractal based on your shape classes (40 points) For this part of the project, we will write a Java program that uses your shape classes to draw a fractal. To help you out, weve already implemented a Canvas class that supports all of the drawing capability you need. You should look at the code if youre interested, but all youll need to know is how you can interact with Canvas objects. Here are the method specifications of the Canvas class: Canvas() (default constructor): creates drawing of default size Canvas(int height, int width): creates drawing of specified width and height void drawShape(Circle circleObj) void drawShape(Rectangle rectangleObj) void drawShape(Triangle triangleObj) Each of the drawing methods will draw the shape you pass it in the specified location and in the specified color. Heres an example of how you might use the Canvas class to draw a blue circle: Canvas drawing = new Canvas(800,800); Circle myCircle = new Circle(0,0,100); myCircle.setColor(Color.BLUE); drawing.drawShape(myCircle); Your task is to write a Java program that uses your shapes and our Canvas class to draw a fractal. Fractals are geometric patterns that repeat on themselves at smaller and smaller scales. They have been studied for centuries because of their interesting mathematical properties and often appear in natural objects (e.g. snow flakes, plants). You can read more about fractals and their history here: http://en.wikipedia.org/wiki/Fractal. Consider the example below, which illustrates the process of constructing a fractal composed of triangles at several steps in the process. Notice that at each step, triangles of increasingly smaller sizes are drawn at the three points of each existing triangle. Your goal is to write a Java program that uses your shape classes and our Canvas class to draw a fractal like this. For full credit, your program should have the following features: ask the user for input (choices: circle, triangle, or rectangle) and use the corresponding shape as the base shape of your fractal draw a pattern that repeats on itself at least 7 times compute the total area of any shapes that form your fractal and print the result to the screen after your program is finished drawing Note that to receive full credit, your program will need to be able to draw a fractal for all three possible inputs (circle, triangle, or rectangle). We suggest that the most convenient implementation is to simply implement three different methods, one that draws a circle fractal, one that draws and triangle fractal, and one that draws a rectangle fractal.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions