1 public class Parallelogram extends Polygon { 2 3 // Instance variables: 4 protected double width, height, angle; 5 6 // Constructors: 7 public Parallelogram(double width, double height, double angle) { 8 setWidth(width); setHeight(height); setAngle(angle); 9 } 10 public Parallelogram(Dimension d, double angle) { 11 setDimension(d); setAngle(angle); 12 } 13 public Parallelogram() { } 14 15 // Encapsulate the instance variables: 16 public void setWidth(double width) { 17 this.width = width; 18 } 19 public void setHeight(double height) { 20 this.height = height; 21 } 22 public void setDimension(double width, double height) { 23 setWidth(width); setHeight(height); 24 } 25 public void setDimension(Dimension d) { 26 setWidth(d.width); setHeight(d.height); 27 } 28 public void setAngle(double angle) { 29 this.angle = angle; 30 } 31 public double getWidth() { 32 return width; 33 } 34 public double getHeight() { 35 return height; 36 } 37 public Dimension getDimension() { 38 return new Dimension(width, height); 39 } 40 public double getAngle() { 41 return angle; 42 } 43 44 // Instance methods: 45 public double perimeter() { 46 return 2*(width + height); 47 } 48 public double area() { 49 return width*height*Math.sin(angle); 50 } 51 52 }