Write an inheritance hierarchy for class Quadrilateral, Trapezoid, Parallelogram
ID: 3622500 • Letter: W
Question
Write an inheritance hierarchy for class Quadrilateral, Trapezoid, Parallelogram, Rectangle, and Square. Use Quadrilateral as the super class of the hierarchy. Make the hierarchy as deep I.e., as many levels) as possible. Specify the instance variables and methods for each class. The private data of the Quadrilateral should be the x-y coordinate pairs for the four end-points of the Quadrilateral. Write a program that instantiate objects of you classes and outputs each object area (except Quadrilateral)Explanation / Answer
/* * Main.java * * Created on August 31, 2007, 1:39 AM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package quadrilateraltest; /** * * @author Al */ public class Main { /** Creates a new instance of Main */ public Main() { } /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Quadrilateral quadrilateral = new Quadrilateral(1.1, 1.2, 6.6, 2.8, 6.6, 9.9, 2.2, 7.4); Trapezoid trapezoid = new Trapezoid(0.0, 0.0, 10.0, 0.0, 8.0, 5.0, 3.3, 5.0); Parallelogram parallelogram = new Parallelogram( 5.0, 5.0, 11.0, 5.0, 12.0, 20.0, 6.0, 20.0 ); Rectangle rectangle = new Rectangle( 17.0, 14.0, 30.0, 14.0, 30.0, 28.0, 17.0, 28.0 ); Square square = new Square( 4.0, 0.0, 8.0, 0.0, 8.0, 4.0, 4.0, 4.0 ); System.out.printf("%s %s %s %s %s ", quadrilateral, trapezoid, parallelogram, rectangle, square ); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.