Ask Question, Ask an Expert

+1-415-315-9853

info@mywordsolution.com

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.
Fractal

  • 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
v)
Constructor; takes four parameters to initialize the Point object, width, length and level; calls the makeWindow( ) method

 Application:

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

Write an mdi project that is a simple text editor allow the

Write an MDI project that is a simple text editor. Allow the user to open multiple documents, each in a separate child form. For the text editor, use one big textbox control with its multiline property set to True or a R ...

Write a program that prompts the user to enter length and

Write a program that prompts the user to enter length and width dimensions for each room in a proposed house so that total floor space can be calculated for the entire house. After each length/width entry, ask the user i ...

Assignmenta talent competition has 5 judges each of whom

Assignment A talent competition has 5 judges, each of whom awards a score Resolved Question: A talent competition has 5 judges, each of whom awards a score between 0 and 10 to each performer. Fractional scores, such as 8 ...

Develop a program that displays information about a family

Develop a program that displays information about a family member or friend. This program should print out information about what you like best about him or her. You might even describe your pet, if you have one. Present ...

Project on grammarsnbspcourseist 230cmpsc

PROJECT ON GRAMMARS   Course: IST 230/CMPSC 360   Deadline: see the calendar in Canvas for the deadline   Objective: To acquire a comprehensive understanding of the application of grammars and formal language theory to c ...

Assignmentthe assignment is as follows use the program

Assignment The assignment is as follows: Use the program, Arrays of Pointers, on p. 188 of the text "Ch. 4, of Ivor Horton's Beginning Visual C++ 2010" as a starting point for this assignment. Refer to Appendix C for ful ...

A certain loop requires 5 loads 7 stores and 8 arithmetic

A certain loop requires 5 loads, 7 stores, and 8 arithmetic operations. What is the minimum initiation interval for a software pipelining of this loop on a machine that executes each operation in one clock tick, and has ...

Fr each of the following c assignment statementsa x a

For each of the following C assignment statements a) x = a + b*c; b) x = a/(b+c) - d*(e+f); c) x = a[i] + 1; d) a[i] = b[c[i]]; e) a[i][j] = b[i][k] + c[k][j]; f) *p++ = *q++; generate three-address code, assuming that a ...

Assignment testing and quality assurancenote this is part

Assignment: Testing and Quality Assurance Note: This is part three of a four-part implementation plan that will be combined to form the finalized plan in Week Four. It is expected that adjustments will be made in the fin ...

Write a lex program that converts a le to pig latin

Write a Lex program that converts a le to Pig Latin." Specially, assume the le is a sequence of words (groups of letters) separated by whitespace. Every time you encounter a word: 1. If the First letter is a consonant, 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

Section onea in an atwood machine suppose two objects of

SECTION ONE (a) In an Atwood Machine, suppose two objects of unequal mass are hung vertically over a frictionless

Part 1you work in hr for a company that operates a factory

Part 1: You work in HR for a company that operates a factory manufacturing fiberglass. There are several hundred empl

Details on advanced accounting paperthis paper is intended

DETAILS ON ADVANCED ACCOUNTING PAPER This paper is intended for students to apply the theoretical knowledge around ac

Create a provider database and related reports and queries

Create a provider database and related reports and queries to capture contact information for potential PC component pro

Describe what you learned about the impact of economic

Describe what you learned about the impact of economic, social, and demographic trends affecting the US labor environmen