import java.awt.Graphics; import java.awt.Color; class CourseSquare { protected int centerX, centerY, side; public CourseSquare() { centerX = centerY = 20; side = 10; } // default constructor public CourseSquare(int cx, int cy) { centerX = cx; centerY = cy; side = 10; } // constructor public CourseSquare(int cx, int cy, int s) { centerX = cx; centerY = cy; side = s; } // constructor public void paint(Graphics g) { g.drawRect(centerX - side/2, centerY - side/2, side, side); } // paint public double getArea() { return side * side; } // getArea public int getCenterX(){ return centerX; } public int getCenterY(){ return centerY; } public int getSide(){ return side; } } // CourseSquare class ColoredSquare extends CourseSquare { protected Color theColor; public ColoredSquare() { super(); theColor = new Color((int)(Math.random()*156) + 100, (int)(Math.random()*156) + 100, (int)(Math.random()*156) + 100); } // default constructor public ColoredSquare(int cx, int cy) { super(cx, cy); theColor = new Color((int)(Math.random()*156) + 100, (int)(Math.random()*156) + 100, (int)(Math.random()*156) + 100); } // constructor public ColoredSquare(int cx, int cy, int side, int r, int g, int b) { super(cx, cy, side); theColor = new Color(r, g, b); } // constructor public void paint(Graphics g) { Color oldColor = g.getColor(); g.setColor(theColor); g.fillRect(centerX - side/2, centerY - side/2, side, side); g.setColor(oldColor); } // paint public Color getColor(){ return theColor; } } // ColoredSquare