Question

I don't know if I'm properly calling a GOval method. My goal is to create the Target corporation logo but with 5 circles. I'm supposed to have the Target symbol centered in the window and have the number of the circles and dimensions controlled by the named constants.

I'm starting with GOval bigCircle and that is my most outer filled circle in color red. Am I properly incorporating the createFilledCircle method?

I only have three circles so far because we're building off a previous assignment and that assignment only had three circles. Also how does N_CIRCLE fit into the picture?

import acm.program.*;
import acm.graphics.*;
import java.awt.*;


public class TargetSymbol extends GraphicsProgram {

public void run(){

    double x = getWidth() / 2;
    double y = getHeight() / 2;




    GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);
    createFilledCircle.setFilled(true);
    createFilledCircle.setColor(Color.RED);
    add(createFilledCircle);        

    GOval middleCircle = new GOval(100, 100, 200, 200);
    middleCircle.setFilled(true);
    middleCircle.setColor(Color.WHITE);
            add(middleCircle);      



    GOval innerCircle = new GOval(155, 150, 100, 100);
    innerCircle.setFilled(true);
    innerCircle.setColor(Color.RED);
    add(innerCircle);






}
private GOval createFilledCircle(double x, double y, double r, Color color){
    GOval circle = new GOval( x-r, x-y, 2 * r, 2 * r);
    circle.setColor(color);
    circle.setFilled(true);
    return circle;


}


private static final int N_CIRCLE = 5; 
private static final double OUTER_RADUS = 75;
private static final double INNER_RADIUS = 10;
Was it helpful?

Solution

I would say you have the right idea.

GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);
createFilledCircle.setFilled(true);
createFilledCircle.setColor(Color.RED);

There is no variable called createFilledCircle, so you can't set it to be filled, or set it's color. We could change it to bigCircle, but that would be redundan, as you're already setting those values in the createFilledCircle() method.

I would just recommend you get rid of those 2 parts altogether, leaving you with:

GOval bigCircle = createFilledCircle(x - OUTER_RADIUS, y - OUTER_RADIUS, 2 * OUTER_RADIUS, 2 * OUTER_RADIUS);

N_CIRCLE, I can only assume represents the number of circles there are. For example, if N_CIRCLE is 5, there's the red outer circle, the white circle inside that, a red circle inside that white circle, etc.

Thus you want to use a loop that creates the circles relative to the amount of circles you have (N_CIRCLE).

e.g.

for(int a = 0; a < N_CIRCLE; a++)
{
    Create a circle that is smaller than the outer one
    Set it's color/fill etc.
}

OTHER TIPS

I did this same assignment and I successfully completed it using this code. I apologize for it being sloppy and in bad form; I wrote it when I was first learning how to write in Java.

/*
 * File: Target.java
 * Name: 
 * Section Leader: 
 * -----------------
 * This file is the starter file for the Target problem.
 */

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class Target extends GraphicsProgram {   
public void run() {
    /* You fill this in. */

    double moveX = getWidth()/2 - 36;
    double moveY = getHeight()/2 - 36;

    GOval outerRed = new GOval(72, 72);
    outerRed.setFilled(true);
    outerRed.setColor(Color.RED);
    outerRed.setFillColor(Color.RED);
    outerRed.move(moveX, moveY);

    GOval middleWhite = new GOval(12.6, 12.6, 46.8, 46.8);
    middleWhite.setFilled(true);
    middleWhite.setColor(Color.WHITE);
    middleWhite.setFillColor(Color.WHITE);
    middleWhite.move(moveX, moveY);

    GOval innerRed = new GOval(25.2, 25.2, 21.6, 21.6);
    innerRed.setFilled(true);
    innerRed.setColor(Color.RED);
    innerRed.setFillColor(Color.RED);
    innerRed.move(moveX, moveY);

    add(outerRed);
    add(middleWhite);
    add(innerRed);
}
}

Here is my solution to this using constants:

/*
 * File: Target.java
* Name: 
* Section Leader: 
* -----------------
* This file is the starter file for the Target problem.
*/

import acm.graphics.*;
import acm.program.*;
import java.awt.*;

public class Target extends GraphicsProgram {   
    private static final int RADIUS_OUTER_CIRCLE = 72;
    private static final int RADIUS_MID_CIRCLE = 54;
    private static final int RADIUS_INNER_CIRCLE = 32;

    public void run() {

        GOval outerCircle = new GOval(getWidth()/2 - RADIUS_OUTER_CIRCLE/2 , getHeight()/2 - RADIUS_OUTER_CIRCLE/2, RADIUS_OUTER_CIRCLE, RADIUS_OUTER_CIRCLE);
        outerCircle.setFilled(true);
        outerCircle.setFillColor(Color.RED);
        add(outerCircle);

        GOval midCircle = new GOval(getWidth()/2 - RADIUS_MID_CIRCLE/2 , getHeight()/2 - RADIUS_MID_CIRCLE/2, RADIUS_MID_CIRCLE, RADIUS_MID_CIRCLE);
        midCircle.setFilled(true);
        midCircle.setFillColor(Color.WHITE);
        add(midCircle);

        GOval innerCircle = new GOval(getWidth()/2 - RADIUS_INNER_CIRCLE/2 , getHeight()/2 - RADIUS_INNER_CIRCLE/2, RADIUS_INNER_CIRCLE, RADIUS_INNER_CIRCLE);
        innerCircle.setFilled(true);
        innerCircle.setFillColor(Color.RED);
        add(innerCircle);

    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top