Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me code the following in: JAVA! Please read the instructions THOROUGHLY and use many COMMENTS! Full points will be awarded, thanks in advance!

Please help me code the following in: JAVA!

Please read the instructions THOROUGHLY and use many COMMENTS!

Full points will be awarded, thanks in advance!

image text in transcribed PolyDemo class: import java.util.*; import javax.swing.*; import java.awt.*; class PolyDemo extends JFrame { public PolyDemo() { getContentPane().add( new PolyDemoPanel() );//just some windowing stuff that must happen for all Frames setSize( 300,300 ); setVisible( true ); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); } public static void main( String args[] ) { PolyDemo myApp = new PolyDemo(); } //this is our first "inner" or internal class //the purpose of this class is solely to support the JFrame class above, and I don't want it reused in arbitrary contexts, so by nesting this class here //I can indicate the intent a bit more clearly that this class "goes with" the class above it //In general, each class is a separate entity that should be contained in a separate file public class PolyDemoPanel extends JPanel { Shape[] myShapes= new Shape[20]; public PolyDemoPanel() { //Shape a = new Shape( getRandInt(), getRandInt()); //Shape b = new Circle( getRandInt(), getRandInt(), getRandInt() ); //a = new Square(getRandInt(), getRandInt(), getRandInt(), getRandInt() ); //a = getRandShape(); //( (Circle) b ).getRadius(); /****************************************************************************************************************** * Code for populating our myShapes changes minimally when new classes are introduced (only in getRandShape()) *************************************************************************************************************/ for( int i = 0; i

Shape class:

import java.awt.*;

/* Class Shape

* This is the superclass in a hierarchy of shapes that you have to construct

*/

//the superclass in our inheritance hierarchy

//all "common" features, functions and data should go here

//for example, all shapes in Java2D have a x,y that declares their position

//and many of the shapes exposed have a width and a height (but not all, so we didn't put width and height here)

/ote that this class is mostly empty, as there is no algorithm generic enough to guess an arbitrary shape's area (future subclasses must override getArea() to provide something reasonable)

//also, the draw method is empty too, as we don't know what shape to draw here! (again, our subclasses will need to replace this method with one that actually draws things)

class Shape extends Object {

private int x = 0;

private int y = 0;

public Shape( int a, int b ) {

x=a;

y=b;

}

public double getArea(){ return -1; }

public void draw( Graphics g ){

}

public int getX() {

return x;

}

public int getY() {

return y;

}

}

6. Fractals& Depth-Limited Recursion In this next section, we'll create a new Shape Subclass that uses recursion to create a fractal snowflake pattern. We'll manage the size of our flakes (as well as the number of recursive calls) using an integer called "limit". This value will provide us with a way to abort the recursion after a specified number of recursive calls -this technique is known as depth-limited recursion, and is frequently used in graphics applications such as fractal design and reverse ray-tracing. 1. Download PolyDemo.java and Shape.java from the last homework. 2. Build a new class called FractalFlake.java that extends Shape a. Define a private final int to manage the snowflake'slimit. i. These should be values such as f1. 50) b. Define a second private final int to manage the number of branches for the flake i. These should be between f5..12) Build a suitable constructor for FractalFlake that invokes the superclass constructor as the first ine of code. 3. In our examples, these flakes will have a size variable, which you should pass to the constructor for your FractalFlake to store Our FractalFlake also has a branching factor, which should be handed to the constructor for our class to manage. a. b. Override the draw function so that it invokes a second draw function that takes more parameters than just the Graphics object, as in: @override public void draw (Graphics g) //a redirect or facade 4. draw (g,getX (, getY ),1imit)

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

More Books

Students also viewed these Databases questions