package cse1030; import java.awt.Color; import princeton.introcs.StdDraw; /** * An ellipse shape. An ellipse has a width and height, both of which are always greater than zero. * * @author CSE1030Z * */ public class Ellipse extends Shape { private double width; private double height; /** * Create an ellipse with position (0, 0), color blue, width 1, and height 0.5 */ public Ellipse() { // make sure to call the superclass constructor first } /** * Create an ellipse with position (x, y), and the given width, height, and color. * * @param x the x coordinate of the position of the ellipse * @param y the x coordinate of the position of the ellipse * @param width the radius of the ellipse * @param height the radius of the ellipse * @param color the color of the ellipse * @throws IllegalArgumentException if either the width or height is zero or negative */ public Ellipse(double x, double y, double width, double height, Color color) { // make sure to call the superclass constructor first } /** * Create an ellipse with the given position, width, height, and color. * * @param position the position of the ellipse * @param width the radius of the ellipse * @param height the radius of the ellipse * @param color the color of the ellipse * @throws IllegalArgumentException if the width or height is zero or negative */ public Ellipse(Point2D position, double width, double height, Color color) { // make sure to call the superclass constructor first } /** * Get the width of the ellipse. * * @return the width of the ellipse */ public double getWidth() { } /** * Set the width of the ellipse. * * @param newWidth * the new width of the ellipse * @throws IllegalArgumentException if the new width is zero or negative */ public void setWidth(double newWidth) { } /** * Get the height of the ellipse. * * @return the height of the ellipse */ public double getHeight() { } /** * Set the height of the ellipse. * * @param newHeight * the new width of the ellipse * @throws IllegalArgumentException if the new height is zero or negative */ public void setHeight(double newHeight) { } /** * Returns a string representation of the ellipse. * *
* The string returned has the form: * *
* position: (x, y), color: (r, g, b), width: W, height: H
where x
* and y
are the coordinates of the position,
* r
, g
, and b
are the
* red, green, and blue components of the color in the range 0-255,
* W
is the width, and H
is the height.
*
* @return a string representation of the ellipse
*/
@Override
public String toString() {
// consider using super.toString()
}
/**
* Draws a filled ellipse to StdDraw
using the
* position, width, height, and color of this ellipse.
*/
@Override
public void draw() {
// use StdDraw.setPenColor first
// then use StdDraw.filledEllipse
// for StdDraw.filledEllipse, the semiMajorAxis is half the width and
// the semiMinorAxis is half the height
}
}