Ask Question, Ask an Expert


Ask Programming Language Expert

The Problem and Requirements

In this Project your task is to create a program that displays various levels of the fractal structure of the so called square shaped Sierpinski-carpet. The display of level 4 is shown below:

503_square shaped Sierpinski-carpet.jpg

  • GUI has two buttons to control level, one of them increases, the other decrease this parameter. The buttons are hosted by the panel at the NORTH region. Approximate fractal is shown at the CENTER region.
  • To draw a given level all the smaller levels down to 1 must also be drawn, each four times on the divided smaller squares, hence a recursive drawing method must be implemented.
  • Level 1 is just a yellow background square with no dividing blue strips. At level 2 the yellow square appears to be divided into four smaller squares by the vertical and a horizontal strip colored blue.
  • At each step to the next level each yellow square is further divided by narrower blue strips.
  • The size of the blue strips is always decreased by same proportion.
  • Increase the level until yellow regions disappear and take note of the highest level at which yellow is still visible.

Analysis and Design
You have to define two classes: Fractal and Application for this program.

  • This class is responsible for the GUI (the frame and the graphics) and for running the recursive drawFractal( ) method.
  • Fractal extends JFrame and implements ActionListener.
  • Fractal has an inner class Centerthat extends JPanel. It represents the center panel and the graphics on it. The innerclass implements the paint method which in turn calls the drawFractal( ) method.
  • Data fields (suggested) :

i) num, denom; publicintegers for the numerator and denominator of the shrinkage ratio

ii) point; a Point reference variable. Point is class in java.awt with two public int fields x and y. Point objects make it easier to reference points on the screen. Being public, direct references point.x and point.y are available for the coordinates; point always identifies the upper left corner of the current (sub)square in the fractal

iii) width, hight; int variables for the dimensions of the current square in the fractal (NOT the dimensions of the frame)

iv) level; int to store the fractal level
v) up, down; JButtons

  • Methods:

i) changeFractal( ) ; sets the title of the whole frame showing the current level; instantiates a Center object (inner class) and adds the object to the pane; calls setVisible( )
ii) actionPerformed( ); mandatory for the buttons; adjusts the level value according to the button clicks and calls changeFractal( )
iii) makeWindow( ) builds and displays frame as shown on a template (without the colored fractal); registers the buttons; use 700, 800 when you set the size
iv) drawFractal( ); takes five parameters as follows: a Graphics reference, a Point reference, integers for level, width and height; the method needs three local variables for Point references: top, side, inside. These reference the upper left corners of the three new smaller squares at the upper right, lower left and lower right positions. Having the three new points and the width and length values determined according to the shrinkage ratio, the method calls itself four times using the four new sets of parameters. Note that the upper left corner of the upper left square is the same as the point reference of the caller method. Do not forget to handle the base case and the coloring
Constructor; takes four parameters to initialize the Point object, width, length and level; calls the makeWindow( ) method


This class has the main method where you:

  • declare and instantiate a Fractal object; initialize the fields with the parameters new Point(60,60), 600, 600, 0

  • initializenum and denom to 9 and 20.

 Documentation and Style:

The program should conform with the Java Documentation and Style Requirements as set by the Computer Science Department. Emphasis will be placed on having the required banner and internal comments, indentation, and overall professional appearance. Comments must be clearly written with correct grammar and spelling.

Programming Language, Programming

  • Category:- Programming Language
  • Reference No.:- M9296

Have any Question? 

Related Questions in Programming Language

Object oriented system analysis and design1non-functional

Object Oriented System Analysis and Design 1. Non-Functional Requirements a) Analysis of NFRs Analyse the Case Study documents and determine the non-functional requirements (NFRs) or system quality attributes necessary t ...

Consider the following three programswhere i k l are low

Consider the following three programs: where i, k, l are low variables and a, b, c, d, h, n are high variables. Assume db is a database with two columns (shown as array, where the index represents the row), lookup and is ...

Csis program homeworkwrite a program where the user will

CSIS program homework Write a program where the user will enter a number between 1 and 50 representing a state. The program should display the full name of that state. Assume the states are in alphabetical order, that is ...

Your problem is as followswrite a program that will ask the

Your problem is as follows: Write a program that will ask the user to enter 4 quiz scores for 3 students.  You will need to fine the lowest quiz grade and drop it out when you calculate the average. You will need to disp ...

Shell programmingyou have created the directory structure

Shell Programming You have created the directory structure and some base files to be used by the Web server and Web site. For the Web site to be created in a production environment, you need to package your commands in a ...

1 implement dfs by using prolog2 implement bfs by using

1. Implement DFS by using PROLOG. 2. Implement BFS by using PROLOG. 3.  Solve the problem of Question 3 in Assignment 1 by using your PROLOG programs of DFS and BFS, respectively. Question 3 from Assignment 1 to Solve wi ...

Part a-1 what arguments can you make for the idea of a

Part A- 1. What arguments can you make for the idea of a single programming language for all programming domains? It would be ideal to have a single programming language for all 2. What arguments can you make against the ...

This assignment introduces you to the perl language and cgi

This assignment introduces you to the Perl language and CGI programming. You will use your scripting and html skills to build a Perl program that will gather user input to then generate a personal webpage. This program w ...

Assignmentcase problem1 - online trivia found on pages

Assignment: Case Problem1 - Online Trivia found on pages 794-795 of your textbook. Complete the web pages and upload them to your 000WebHost account. After uploading the files make sure to update your index.html page to ...

Operating systems assignment-1 binary record sorting in

Operating Systems Assignment- 1. Binary Record Sorting in Ascending Order| You will write a simple sorting program. This program should be invoked as follows: shell% ./fastsort -i inputfile -o outputfile The above line m ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

A cola-dispensing machine is set to dispense 9 ounces of

A cola-dispensing machine is set to dispense 9 ounces of cola per cup, with a standard deviation of 1.0 ounce. The manuf

What is marketingbullwhat is marketing think back to your

What is Marketing? • "What is marketing"? Think back to your impressions before you started this class versus how you

Question -your client david smith runs a small it

QUESTION - Your client, David Smith runs a small IT consulting business specialising in computer software and techno

Inspection of a random sample of 22 aircraft showed that 15

Inspection of a random sample of 22 aircraft showed that 15 needed repairs to fix a wiring problem that might compromise

Effective hrmquestionhow can an effective hrm system help

Effective HRM Question How can an effective HRM system help facilitate the achievement of an organization's strate