I am not sure where to put my if statements because I get an error when in the constructor and I'm not sure where else to put them.
import java.awt.Color;
/**
* Create a class called GrowingDot. This will draw a circle on the screen
* in a specified color. Every time it is drawn it will increase
* in size until it reaches a maximum size and then it will be reset
* to its minimum size and start growing again.
*
* The class will need 4 class variables. Declare 3 ints (the x, y location
* of the circle and the size of the circle).
* The class will also need a Color variable to store the circle's color.
*
* Create a Constructor that takes two ints and a Color object as
* parameters. These represent the x, y coordinates of the circle
* (in that order) and its color. Use the parameters to set the
* appropriate class variables.
*
* If the x parameter is less than 0, set the class's variable to 0.
* Otherwise, use the value of the parameter. The same should be done
* with the y parameter.
*
* If the Color object is null, set the class's variable to red.
* Otherwise, use the value of the parameter.
*
* For the size of the circle, it should start off at 5.
*
* Create a getX method that returns an int and takes no parameters. This
* should return the x coordinate of the circle.
*
* Create a getY method that returns an int and takes no parameters. This
* should return the y coordinate of the circle.
*
* Create a getColor method that returns a Color and takes no parameters.
* This should return the color of the circle.
*
* Create a setPosition method that takes two int parameters (the x, y
* coordinates) and returns nothing. If the x parameter is greater than
* or equal to 0, update the class's variable to the parameter's value.
* Otherwise, do nothing. Do the same with the y parameter.
*
* Create a display method that takes a Graphics object as its parameter and
* returns nothing. Using the Graphics object draw a filled oval using
* the class's size variable for its dimensions and the Color variable
* for the color. Use the class's x, y variables as
* the coordinates for the circle.
*
* After the circle has been drawn, increase the size variable by 1. If the
* new size is greater than 10, change it to 5.
*
* Make sure you format it and include the needed documentation.
*/
public class GrowingDot {
int x;
int y;
int location;
Color c;
public GrowingDot(int x1, int y1, Color color) {
x = x1;
y = y1;
c = color;
if (x1 < 0) {
return x = 0;
return x1;
}
if (y1 < 0) {
return y = 0;
return y1;
}
if (color = null) {
return c = red;
return color;
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire