Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are developing a simple graphics package that will allow you to draw and man

ID: 3555056 • Letter: Y

Question

You are developing a simple graphics package that will allow you to draw and manipulate simple geometric shapes such as squares, rectangles, etc. Your initial design is along the following lines:

public class Rectangle {

   private int h, w;

   public int getHeight() {

Explanation / Answer

private int height,width; public Rectangle(int x,int y) { super(x,y); } public Rectangle(int x ,int y,int width ,int height){ super(0, 0,x,y); setWidth(width); setHeight(height); } public void setWidth(int w){ if( w > 0 )width=w; } public void setHeight(int h){ if(h > 0)height=h; } public int getWidth(){return width;} public int getHeight(){return height;} public void Draw(java.awt.Graphics g) { g.drawRect(x0+x, y0-y, width,height); } } public class Square extends Rectangle{ private int side; public Square(int x ,int y ) { super(x,y); } public Square(int x, int y,int side){ super(side,side); } public int getSide() { return getWidth(); } public void setSide(int side) { super.setWidth(side); super.setHeight(side); } public void setWidth(int width) { this.setSide(side); } public void setHeight(int width) { this.setSide(side); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote