Write a program that uses recursion to draw squares- one square on the corner of each square.

Presupuesto $10 - $30 USD
Ofertas 8
Oferta promedio $53
Estado Cerrado

Write a program that uses recursion to draw squares- one square on the corner of each square. You can write an applet or a standalone GUI program. Either is fine.


Your program should have instance data that defines:

the initial size of the largest square

the minimum length of a size of a square

by what factor you shrink the size for each round of squares

Your program will include a recursive method to draw a square.

The method should draw one square (the small part of the problem it solves now).

The method should then recursively call itself to draw the four squares at the corner of the current square. (The sides of these smaller squares are reduced by some factor.)

The recursive method should be initially invoked once from the paint or paintComponent method.


What parameters should that method have?

What initial values are sent into the first call to this method?

When does the method stop (what is the base case)?


In my sample below, I use an initial side length of 200, a minimum side length of 10, and I cut the size of a side in half each time.

You do not have to use these values- experiment with your own.

In the sample, I fill the square in gray and then draw the outline in black. You are not required to do this.

I include a couple versions of the sample output below. You only need to submit one version of your program.

I recommend first getting the program working with using a method to draw a single square.

I strongly recommend sketching out the coordinates on paper before attempting to put them into code.

I have provided template code that you can use to start from for an applet or a standalone program. You are not required to use this.

Extra Credit

(15 points) Instead of drawing a square, draw a different polygon (e.g., any closed-sided figure but not a circle, square, or rectangle). It could be a triangle, parallelogram, trapezoid, be creative!

Note: If completing the extra credit, you do not need to do both the square version and the extra credit- you can complete only the extra credit.

If you want to see what this looks like with fewer squares, to get a better sense of what is going on, here are two images that use a minimum side length of 50 and 100.

Obtén cotizaciones gratis para un proyecto como este

¿Buscas ganar algo de dinero?

  • Establece tu presupuesto y el plazo
  • Describe tu propuesta
  • Recibe dinero por tu trabajo

Ofertas en este proyecto

  • utkarshkatiyar19 Profile Picture


    kanpur,  India

    Hi, I have good knowledge of C/C++/Java/Python programming on Linux, Windows and Mac OS. I have knowledge about Mathematics , and any Computer related concept such as Algorithms, Data Structures, Networking, Cryptography, Databases, Operating Systems , Compilers, Data Mining etc. I also have experience related to web. Feel free to discuss your project with me in these domains or any other relevant domain. I ensure 24*7 Support.

  • Pelozo Profile Picture


    Partido de la costa,  Argentina

    - Android 4.0+ Development . - Java Development. - Python Development. - Web Service Development using PHP/MySQL, JSON.

  • wangbeizou Profile Picture


    Dalian,  China

    Hello, We are a team of skilled dedicated people and our passion is simply to excite ourselves with every project that we do. Our team work experience is of more than 5 years combined while enthusiasm and fresh creative minds is the driving force for our team. Every single team member is the task manager who takes complete ownership and that mentality is set in everyone who works on your project. We are a dynamic learning organization willing to accept changes, challenges, hurdles and see an opportunity out of it both for tasks and clients alike. One for all and all for one is the comradely that is experienced in within the team which shows in our projects where we are always directed to make your story , a successful one.

  • nwlfst Profile Picture


    Kushtia,  Bangladesh

    Hi I can do any work in time and also try my best to do perfectly. I am an Engineer and experience in online marketing.

  • rainbow Profile Picture


    Nagpur,  India

    Doing software development for last 20 year. The work in java , oracle ,mysql, C++ languages is undertaken. Web site designing and web page development

  • sagar4u123 Profile Picture


    KOLKATA,  India

    Have 5+ Years of programming experience in Java,J2EE, Struts , Spring, Hibernate, JSP . Also have experience in JSF.

  • moonpower626 Profile Picture


    dandong,  China

    Hello, everybody! I am a new freelancer but I am a powerful IT expert with over 8 years experience. I will work for you and for my success. I am specialized in 1) desktop applications(c/c++, java/javafx, c#/.net, objective-c, python, ....), 2) web pages(html, javascript, php, , angular-js, jsp, jquery, boostrap, ext-js, ), 3) mobile applications(native, phonegap) and games with cocos2d, cocos2dx and unity, 4) assembling, analysing and extracting data, .... 5) OCR(Desktop, Android, iOS), DriverLicenseCard Recognition with 100% accuracy, CarNumberRecognition, Surveillance System, BarcodeReader(1d, 2d, pdf417...) 6) Database(mysql, sqlite, MS-SQL, Access, Oracle,...), I will be happy to work with you. I hope long time relationship with you and i will try my best for our success. I also have many great programmers, so you will get best result. thanks!

  • MIQ11 Profile Picture


    BETUL,  India

    Skilled in Web Application Development as well as Stand Alone Applications. Well versed in different front ends and languages like C++/ Java/ .net/ pHp, etc. as well as back ends including MySQL, Oracle, etc.