Put the right code into TODO sections:

import javax.swing.*;
import java.awt.image.BufferedImage;
import java.util.Scanner;
import java.awt.Graphics;
import javax.imageio.ImageIO;
import java.awt.Container;
import java.awt.Graphics2D;

public class Lastname_FractalGenerator extends JComponent{

private static JFrame frame;

public static void main(String[] args){

//TODO: Implement required code to save the fractal image to file

* Draw a fractal image using recursion
* @param x      The x coordinate of the upper left corner of the oval to be drawn.
* @param y      The y coordinate of the upper left corner of the oval to be drawn.
* @param radius Radius of the circle
* @param g      Object used to draw on the canvas
public static void drawFractalUsingRecursion(int x, int y, int radius, Graphics g){
//TODO: Use the method "g.drawOval" to draw a circle
//Parameters are x, y, width of the oval to draw, and height of the oval to draw
//Use recursion to draw the rest of the circles

//Do not change anything below this line
//Do not change anything below this line

* Paints the container
* @param g Auto-generated variable to paint to the container
public void paint(Graphics g) {
int initialRadius = 300;
int x = (int) (frame.getSize().getWidth() / 2 - initialRadius / 2);
int y = (int) (frame.getSize().getHeight() / 2 - initialRadius / 2);
drawFractalUsingRecursion(x, y, initialRadius, g);

* This method will create a canvas with the given width and height
public static void drawCanvas(){
frame = new JFrame();
       frame.getContentPane().add(new Lastname_FractalGenerator());
       frame.setSize(700, 680);
* This method saves a given image to disk
* @param imagePixels Image to be saved
* @param fileName Name of the file
public static void saveImage(String fileName)
fileName += ".jpg";
try {
Container content = frame.getContentPane();
            BufferedImage bi = new BufferedImage(content.getWidth(), content.getHeight(), BufferedImage.TYPE_INT_RGB);
            Graphics2D g2d = bi.createGraphics();

    //Save file
    File outputfile = new File(fileName);
    ImageIO.write(bi, "jpg", outputfile);
} catch (IOException e) {
    System.out.println("Error: " + e.toString());

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Task description
Generate simple fractal image in order to test if fractal images reduce physiological stress. In order to do that, I will draw circles of different radiuses and center coordinates in a recursive manner, terminating recursive iteration when radius of a circle becomes smaller than a predefined minimum value.

Radius (integer) represents a radius of a circle drawn during current recursion run
CentreX (integer) represents x value of a circle centre coordinate
CentreY (integer) represents y value of a circle centre coordinate
RadiusNext (integer) represents a radius of a circle drawn during next recursion run (two times smaller than original one)
CentreXNext (integer) represents next x value of a circle centre coordinate for a next recursion run
CentreYNext (integer) represents next y value of a circle centre coordinate for a next recursion run
RADIUS_MIN (integer) constant presenting minimum accepted value of a radius...

By purchasing this solution you'll be able to access the following files: and Solution.docx.

for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats