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

I need help with the flowchart, pseudocode, and UML diagram. GeometricObject.jav

ID: 3708224 • Letter: I

Question

I need help with the flowchart, pseudocode, and UML diagram.

GeometricObject.java

import java.util.Scanner;

abstract class GeometricObject {
private String color = "white";
private boolean filled;
private java.util.Date dateCreated;

/** Construct a default geometric object */
protected GeometricObject() {
}

/** Construct a geometric object with color and filled value */
protected GeometricObject(String color, boolean filled) {
dateCreated = new java.util.Date();
this.color = color;
this.filled = filled;
}

/** Return color */
public String getColor() {
return color;
}

/** Set a new color */
public void setColor(String color) {
this.color = color;
}

/** Return filled. Since filled is boolean ,
* the get method is named isFilled */
public boolean isFilled() {
return filled;
}

/** Set a new filled */
public void setFilled(boolean filled) {
this.filled = filled;
}

/** Get dateCreated */
public java.util.Date getDateCreated() {
return dateCreated;
}

@Override
public String toString() {
return "created on " + dateCreated + " color: " + color +
" and filled: " + filled;
}

/** Abstract method getArea */
public abstract double getArea();

/** Abstract method getPerimeter */
public abstract double getPerimeter();
}

Triangle.java

import java.util.*;

public class Triangle extends GeometricObject
{
       //variable for sides of triangle
       private double side1;
       private double side2;
       private double side3;      
      
       //default constructor
       public Triangle()
       {
           side1=1.0;
           side2=1.0;
           side3=1.0;
       }
      
       //constructor with parameters
       public Triangle(double side1,double side2,double side3,String color,boolean filled)
       {
             //calling superclass constructor
           super(color,filled);
          
           this.side1=side1;
           this.side2=side2;
           this.side3=side3;
       }
      
       //method to set side1
       public void setSide1(double side1)
       {
           this.side1=side1;
       }
      
       //method to set side2
       public void setSide2(double side2)
       {
           this.side2=side2;
       }
      
       //method to set side3
       public void setSide3(double side3)
       {
           this.side3=side3;
       }
      
       //method to get side1
       public double getSide1()
       {
           return side1;
       }
      
       //method to get side2
       public double getSide2()
       {
           return side2;
       }
      
       //method to get side3
       public double getSide3()
       {
           return side3;
       }
      
       //method to get area
       public double getArea()
       {
           double p;
           double area;
          
           p=getPerimeter()/2;
           //calculating area of the triangle
           area=Math.sqrt(p*(p-side1)*(p-side2)*(p-side3));
          
           return area;
          
       }
      
       //method to get perimeter
       public double getPerimeter()
       {
           return (side1+side2+side3);
       }
      
       //method to get string representation of the object
       public String toString()
       {
          
           return "Area: "+String.format("%.1f", getArea())+" "+
                   "Perimeter: "+String.format("%.1f", getPerimeter())+" "+
                  "Color: "+getColor()+" "+
                  "Filled?: "+isFilled();              
       }  
}

TriangleDriver.java

import java.util.*;

//Driver for Triangle class
public class TriangleDriver
{
   //main method
   public static void main(String args[])
   {
       //scanner object
       Scanner ob=new Scanner(System.in);
      
       //variables to store the sides of triangle
       double side1,side2,side3;
      
       //getting the sides of the triangle
       System.out.print("Enter side1 of triangle: ");
       side1=ob.nextDouble();
      
       System.out.print("Enter side2 of triangle: ");
       side2=ob.nextDouble();
      
       System.out.print("Enter side3 of triangle: ");
       side3=ob.nextDouble();
      
       //getting the color of the triangle
       System.out.print("Enter color of triangle: ");
       String color=ob.next();
      
       //getting filled or not
       System.out.print("Enter whether triangle is filled(yes/no): ");
       String choice=ob.next();
      
       // converting choice to lowercase
       choice=choice.toLowerCase();
      
       boolean filled=false;
      
       // checking yes or not
       if (choice.equals("yes"))      
           filled=true;      
      
       if (choice.equals("no"))
           filled=false;
      
       //creating Triangle object
       Triangle t1=new Triangle(side1,side2,side3,color,filled);
  
       //printing the triangle details
       System.out.println(t1);      
      
   }
}

Explanation / Answer

COPY CODE:

    public Circle() {

    }

    /**

     * Constructor.

     *

     * @param double initial size of the object's radius.

     */

    public Circle(double rad) {

        this.radius = rad;

    }

    /**

     * Accessor.

     *

     * @return double the object member, this.radius

     */

    public double getRadius() {

        return this.radius;

    }

    /**

     * Mutator for the object member this.raius.

     *

     * @param double the new radius for this object.

     */

    public void setRadius(double rad) {

        this.radius = rad;

    }

    /**

     * Compute the area of this object.

     *

     * @return double the Circle's area.

     */

    public double getArea() {

        return this.radius * this.radius * Math.PI;

    }

    /**

     * Compute the diameter of this object.

     *

     * @return double the diameter of this Circle.

     */

    public double getDiameter() {

        return 2 * this.radius;

    }

    /**

     * Compute the perimeter of this object.

     *

     * @return double the perimeter of this Circle.

     */

    public double getPerimeter() {

        return 2 * this.radius * Math.PI;

    }

    /**

     * Implementation of equals().

     * NOTE: Based on the Circles' radius.

    public boolean equals(Object obj) throws Error {

        if (obj instanceof Circle) {

            if (((Circle) obj).radius == this.radius) {

                return true;

            }

            else {

                return false;

            }

        }

        else {

            java.util.Formatter err = new java.util.Formatter();

            err.format("You cannot compare the value of two non-like objects; must use an object of the %s Class, not the %s Class.",

                    this.getClass().getName(), obj.getClass().getName());

            throw new Error(err.toString());

        }

    }

    public int compareTo(Object obj) throws Error {

        if (obj instanceof Circle) {

            double thisArea = this.getArea();

            double otherArea = ((Circle) obj).getArea();

            if (thisArea == otherArea) {

                //objects are the same size

                return 0;

            }

            else if (thisArea < otherArea) {

       

                return -1;

            }

            else {

                return 1;

            }

        }

        else {

            java.util.Formatter err = new java.util.Formatter();

            err.format("You cannot compare the value of two non-like objects; must use an object of the %s Class, not the %s Class.",

                    this.getClass().getName(), obj.getClass().getName());

            throw new Error(err.toString());

        }

    }

    public void printCircle() {

        System.out.printf("This circle was created: %s and the radius is: %.2f",

                getDateCreated(), this.radius);

    }

    //main to main compiler happy

    public static void main(String argv[]) {

    }

}

}

public class ObjectCompare {

    public static Object max(Object[] a) throws Error {

        Object largest = a[0];// = new Object();

        for (int i = 0; i < a.length; i++) {

            if (!(a[i] instanceof Comparable)) {

                java.util.Formatter err = new java.util.Formatter();

                err.format("Object #%.0f of the array being queried is not a child of Comparable.", ++i);

                throw new Error(err.toString());

            }

            if (((Comparable) a[i]).compareTo(largest) > 0) {

                largest = a[i];

            }

        }

       return largest;

    }

}

public class TestCircle {

    public static void main(String argv[]) {

        double baseRad = 4;

        System.out.printf("Testing compareTo() of two Circle object. ");

        Circle circ = new Circle(baseRad);

        System.out.printf(" called circ1 = Circle(%.0f); circ2 = Circle(4). ", baseRad);

        Circle sameObj = new Circle();

        System.out.println(" circ1.compareTo(circ2) = "+ circ.compareTo(sameObj));

        System.out.printf(" called circ1 = Circle(%.0f); circ2 = Circle(3). ", baseRad);

        Circle diffObj = new Circle();

        System.out.println(" circ1.compareTo(circ2) = "+ circ.compareTo(diffObj));

        System.out.printf("Testing equals() of Circle object, circ1, and Object object. ");

        Object genericObj = new Object();

        circ.compareTo(genericObj);

    }

}

public class ObjectTest {

    public static void main(String[] argv) {

        int i;

        int aSize = 10;

        //test strings

        String[] obj1 = new String[aSize];

        System.out.printf("Testing with strings ");

        for (i = 0; i < obj1.length; i++) {

            obj1[i] = "" + i;

            System.out.printf(" ...creating string object #%d of %d: %s ", i+1, obj1.length, obj1[i].toString());

        }

        Object stringTest = ObjectCompare.max(obj1);

        System.out.printf(" largest object is: %s ", stringTest.toString());

        Integer [] obj2 = new Integer[aSize];

        System.out.printf("Testing with integers ");

        for (i = 0; i < obj2.length; i++) {

            obj2[i] = i;

            System.out.printf(" ...creating integer object #%d of %d: %d ", i+1, obj2.length, obj2[i]);

        }

        Integer intTest = (Integer) ObjectCompare.max(obj2);

        System.out.printf(" largest object is: %s ", intTest.toString());

        System.out.printf("Testing with dates ");

        java.util.Date[] obj3 = new java.util.Date[aSize];

        for (i = 0; i < obj3.length; i++) {

            obj3[i] = new java.util.Date();

            System.out.printf(" ...creating Date object #%d of %d: %s (epoch: %d) ", i+1, obj3.length, obj3[i].toString(), (int) obj3[i].getTime());

        }

        java.util.Date dateTest = (java.util.Date) ObjectCompare.max(obj3);

        System.out.printf(" largest object is: %s ", (String) dateTest.toString());

        System.out.printf(" largest object is: %d ", (int) dateTest.getTime());

    }

}