/* * File: Parallelogram.java * * Parallelogram class * * Copyright: Northeast Parallel Architectures Center * */ // A parallelogram is a quadrilateral with parallel sides: public class Parallelogram extends Quadrilateral { // horizontal displacement (from vertical): private int d; // height of parallelogram: private int h; // accessor methods: public int getHeight() { return h; } public int getDisplacement() { return d; } // Parallelogram constructor #1 (assume the included // angle alpha satisfies the inequality 0 < alpha < PI ): public Parallelogram( int x, int y, int a, int b, double alpha ) { // invoke the no-argument constructor of the superclass: super(); // the 'this' reference is optional: this.addPoint( x, y ); this.addPoint( x + a, y ); this.d = ( int ) Math.round( b * Math.cos( Math.PI - alpha ) ); this.h = ( int ) Math.round( b * Math.sin( Math.PI - alpha ) ); this.addPoint( x + a - d, y + h ); this.addPoint( x - d, y + h ); } // Parallelogram constructor #2: public Parallelogram( int x, int y, int a, int b, double alpha, double theta ) { // invoke Parallelogram constructor #1: this( x, y, a, b, alpha ); // rotate the parallelogram theta radians: this.rotate( theta ); } }