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

This hierarchy begins with superclass Shape, which is extended by subclass Geome

ID: 3798167 • Letter: T

Question

This hierarchy begins with superclass Shape, which is extended by subclass Geometricobject- is a shape. Also, Geometricobject is a Comparable (interface) object. The third level of this hierarchy contains specific types of Circle and Rectangle. As in the below figure, we can follow the arrows from the bottom of the diagram to the topmost superclass in this class hierarchy to identify several is-a relationships. For example, a circle is a geometric object and is a shape as well as is a comparable object. interface Comaprable abstract class Shape Geometricobject abstract class Circle Rectangle Requirements: Need to create the following four (4) classes and each class MUST include the code documentations 1. Shape class (20 pts) -abstract class class Variable Constructor/method Shape() Shape -X: int Shape (int, int) -Y: int setX(int x): void and setY(int Y): void getX(): int and +getY(): int getName(): abstract String getArea(): abstract double get Perimeter abstract double

Explanation / Answer

//This is super abstract class of hierarchy
package com.shape;

public abstract class Shape {

   int X;
   int Y;
   //0 arg constructor
   Shape(){
  
   }
   //2 arg constructor
   Shape(int X,int Y){
       this.X=X;
       this.Y=Y;
   }
   public void setX(int X){
       this.X=X;
   }
   public int getX(){
      
       return X;
   }
public void setY(int Y){
   this.Y=Y;
   }
   public int getY(){
       return Y;
   }
   abstract String getName();
   abstract Double getArea();
   abstract Double getPerimeter();
}

//This is derived abstract class of hierarchy
package com.shape;

import java.util.Date;

public abstract class GeometricObject extends Shape implements Comparable {

   String color;
   boolean filled;
Date dateCreated;
  
//0 arg constructor
   GeometricObject(){
      
   }
   //2 arg constructor
GeometricObject(String color,boolean filled){
       this.color=color;
       this.filled=filled;
   }
//4 arg constructor
   GeometricObject( int X,int Y,String color,boolean filled){
       super(X,Y);
       this.color=color;
       this.filled=filled;
   }
  
   public String getColor() {
       return color;
   }
   public void setColor(String color) {
       this.color = color;
   }
  
   public boolean isFilled() {
       return filled;
   }
   public void setFilled(boolean filled) {
       this.filled = filled;
   }
  
   public Date getDateCreated() {
       return dateCreated;
   }
  
   public String toString(){
       return null;
      
   }
  
   @Override
   public int compareTo(Object obj) {
       // TODO Auto-generated method stub
       GeometricObject o=(GeometricObject)obj;
       return 0;
   }
  
   public static GeometricObject max(GeometricObject o1,GeometricObject o2){
      
       if(o1.compareTo(o2)>0)
           return o1;
       else
      
       return o2;
      
   }
  
}

//This is child class of GeometricObject of hierarchy
package com.shape;

public class Rectangle extends GeometricObject {

   double width;
  
   double height;
   //0 arg constructor
   Rectangle(){
      
   }
   //2 arg constructor
   Rectangle(double width,double height){
       this.width=width;
       this.height=height;
   }
   //4 arg constructor
   Rectangle(double width,double height,String color, boolean filled){
       super(color,filled);
       this.width=width;
       this.height=height;
   }
  
   public double getWidth() {
       return width;
   }
   public void setWidth(double width) {
       this.width = width;
   }
   public double getHeight() {
       return height;
   }
   public void setHeight(double height) {
       this.height = height;
   }
  
   String getName(){
       return "Rectangle";
   }
   Double getArea(){
       Double Area=width*height;
       return Area;
   }
   Double getPerimeter(){
       Double Perimeter=width*2+height*2;
       return Perimeter;
   }
  
   public int compareTo(Object obj) {
       // TODO Auto-generated method stub
       GeometricObject o=(GeometricObject)obj;
       return 0;
   }
  
}

//This is child class of GeometricObject of hierarchy
package com.shape;

public class Circle extends GeometricObject {

   double radius;
   //0 arg constructor
   Circle(){
      
   }
   //1 arg constructor
Circle(double radius){
       this.radius=radius;
   }
//3 arg constructor
   public Circle(double radius, String color, boolean filled) {
       super(color,filled);
       this.radius=radius;
      
   }
   public double getRadius() {
       return radius;
   }

   public void setRadius(double radius) {
       this.radius = radius;
   }
  
   String getName(){
       return "Circle";
   }
   Double getArea(){
       Double Area=radius*radius*Math.PI;
       return Area;
   }
   Double getPerimeter(){
       Double Diameter=radius*2;
       Double Perimeter=Diameter*2;
       return Perimeter;
   }
  
   public int compareTo(Object obj) {
       // TODO Auto-generated method stub
       GeometricObject o=(GeometricObject)obj;
       return 0;
   }
  
}

//This is test class to check above classes
package com.shape;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class ShapeTest {

   public static void main(String[] args) {
      
ArrayList<GeometricObject> shapes=new ArrayList();
Circle circle1=new Circle(3.0,"White",true);
Circle circle2=new Circle(6.0,"Red",true);
  
Rectangle rect1=new Rectangle();
Rectangle rect2=new Rectangle(71,96);
  
shapes.add(circle1);
shapes.add(circle2);
shapes.add(rect1);
shapes.add(rect2);
  

//call method to print all
for(GeometricObject currentshape:shapes){
  
   Date dateCreated=new Date();
   SimpleDateFormat sdf=new SimpleDateFormat();
   String s=sdf.format(dateCreated);
   //System.out.println("Created on "+s);
  
   System.out.println(currentshape.getName()+" Created on "+s+" Color:"+currentshape.getColor()+" filled:"+currentshape.isFilled());
  
  
  
   if(currentshape instanceof GeometricObject){
      
     
       //(Circle) currentShape;
       System.out.printf("%s's area is %f ",currentshape.getName(),currentshape.getArea());
      
       //perimeter
       System.out.printf("%s's perimeter is %s ",currentshape.getName(),currentshape.getPerimeter());
      
       System.out.println("---------------------------");
   }//end if
}//end for
  
//Display max circle
Circle circle=(Circle) GeometricObject.max(circle1, circle2);
System.out.println("The max circle radius: "+circle.getRadius());
  
System.out.println("---------------------------");
  
//Display max rectangle
Rectangle rectangle=(Rectangle) GeometricObject.max(rect1, rect2);
System.out.println("The max rectangle width: "+rectangle.getWidth()+"and height"+rectangle.getHeight());
  
   }

}

Output:

Circle Created on 2/25/17 11:20 PM Color:White filled:true
Circle's area is 28.274334
Circle's perimeter is 12.0
---------------------------
Circle Created on 2/25/17 11:20 PM Color:Red filled:true
Circle's area is 113.097336
Circle's perimeter is 24.0
---------------------------
Rectangle Created on 2/25/17 11:20 PM Color:null filled:false
Rectangle's area is 0.000000
Rectangle's perimeter is 0.0
---------------------------
Rectangle Created on 2/25/17 11:20 PM Color:null filled:false
Rectangle's area is 6816.000000
Rectangle's perimeter is 334.0
---------------------------
The max circle radius: 6.0
---------------------------
The max rectangle width: 71.0and height96.0

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