Question: I need a code for a triangle and Tetrahedron shape to go with the following codes which are two dimensional and three dimensional. // Definition

I need a code for a triangle and Tetrahedron shape to go with the following codes which are two dimensional and three dimensional.

// Definition of Shape public abstract class Shape { private int x; // x coordinate private int y; // y coordinate // two-argument constructor public Shape( int x, int y ) { this.x = x; this.y = y; } // end two-argument Shape constructor // set x coordinate public void setX( int x ) { this.x = x; } // end method setX // set y coordinate public void setY( int y ) { this.y = y; } // end method setY // get x coordinate public int getX() { return x; } // end method getX // get y coordinate public int getY() { return y; } // end method getY // return String representation of Shape object public String toString() { return String.format( "[%d, %d]", getX(), getY() ); } // abstract methods public abstract String getName(); } // end shape // definition of twodimensional shape public abstract class TwoDimensionalShape extends Shape { private int dimension1; private int dimension2; // four-argument constructor public TwoDimensionalShape( int x, int y, int d1, int d2 ) { super( x, y ); dimension1 = d1; dimension2 = d2; } // end four-argument TwoDimensionalShape constructor // set methods public void setDimension1( int d ) { dimension1 = d; } // end method setDimension1 public void setDimension2( int d ) { dimension2 = d; } // end method setDimension2 // get methods public int getDimension1() { return dimension1; } // end method getDimension1 public int getDimension2() { return dimension2; } // end method getDimension2 // abstract method public abstract int getArea(); } // end class TwoDimensionalShape

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!