import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Ellipse2D; import java.awt.geom.Rectangle2D; /** * @author Prof. Wittie CS 203, Fall 2009 */ /** * A Soda is a drink that can be ordered with a pizza. A soda is 80 wide and * 180 high when drawn. * */ public class Soda { private double xCoord; private double yCoord; /** * Creates a soda in a cup. * * @param xCoord * the x coordinate of the upper left corner of the bounding box. * @param yCoord * the y coordinate of the upper left corner of the bounding box. */ public Soda(double xCoord, double yCoord) { this.xCoord = xCoord; this.yCoord = yCoord; } /** * Draws the soda and cup at the given top left coordinates. * * @param g2 * the graphics context */ public void draw(Graphics2D g2) { Rectangle2D.Double cup = new Rectangle2D.Double(xCoord, yCoord, 80, 150); Ellipse2D.Double top = new Ellipse2D.Double(xCoord, yCoord - 15, 80, 30); Ellipse2D.Double bottom = new Ellipse2D.Double(xCoord, yCoord + 150 - 15, 80, 30); Ellipse2D.Double soda = new Ellipse2D.Double(xCoord + 5, yCoord - 15 + 5, 70, 20); // http://web.njit.edu/~kevin/rgb.txt.html#Orange g2.setColor(new Color(255, 127, 0)); // DarkOrange1 g2.fill(cup); g2.fill(bottom); g2.setColor(Color.WHITE); g2.fill(top); g2.setColor(new Color(255, 127, 0)); // DarkOrange1 g2.draw(top); g2.setColor(new Color(92, 64, 51)); // darkbrown g2.fill(soda); g2.setColor(Color.BLUE); g2.drawString("BU Cola", (int) xCoord + 15, (int) yCoord + 75); } }