Please program this question in java please and thank you.
Here are the original classes.
Shape class
public abstract class Shape{ public abstract double getArea(); public abstract double getPerimeter();
}//End class Shape
Equilltriangle class
public class EquilTriangle extends Shape{ private double length; public EquilTriangle(double lengthIn){ length = lengthIn; } public String toString(){ return "[Equilateral Triangle: Length: "+length+"]"; } public double getArea(){ double h = length; double o = length/2; return Math.sqrt(h*h-o*o); } public double getPerimeter(){ return length*3; }
}//End class EquilTriangle
Cirlce class.
public class Circle extends Shape{ private double radius; public Circle(double radiusIn){ radius = radiusIn; } public String toString(){ return "[Circle: radius: "+radius+"]"; } public double getArea(){ return Math.PI*radius*radius; } public double getPerimeter(){ return Math.PI*2*radius; }
}//End class Circle
Square class
public class Square extends Shape{ private double length; public Square(double lengthIn){ length = lengthIn; } public String toString(){ return "[Square: Length: "+length+"]"; } public double getArea(){ return length*length; } public double getPerimeter(){ return 4*length; }
}//End class Square
Test class.
public class Test1 { public static void main(String[] args){ // Create several shapes with two that // have the same perimeter and two references // that share the same object. Circle cA = new Circle(2); Circle cB = cA; Circle cC = new Circle(2); Circle cD = new Circle(3); Square sA = new Square(Math.PI); EquilTriangle tA= new EquilTriangle(2); System.out.println("cA.equals(cB): "+cA.equals(cB) ); System.out.println("cA.equals(cC): "+cA.equals(cC) ); System.out.println("cA.equals(cD): "+cA.equals(cD) ); System.out.println("cA.equals(sA): "+cA.equals(sA) ); System.out.println("tA.equals(sA): "+tA.equals(sA) ); } }//End Test1
Here is the question.
These questions below are asked to be answered and I would like them to be done in order please and thank you and in java.
Please program all of this in java.
2. Interfaces and Polymorphism: A. Implement the Comparable interface for the various shapes where the compareTo() method uses the value of perimeter/area as the basis for comparison. Implement in Find.java the following methods using one of the following two ways to handle generic types: 1. As in the textbook (see the Sorting class in Chapter 10): public class Find
; This means the methods will take Comparable arrays and array elements may need to be cast to T (see examples in Chapter 10). Note: this approach will generate a warning about "unchecked or unsafe operations when you compile Find.java, which can be ignored. public Comparable getLargest (Comparable[] a); Returns the largest object in the array public boolean is Present (Comparable[] a, T key); Returns whether a given object (key) is present in the array (using compareTo()) public int presentNTimes (Comparable[] a, T key); A count of the number of occurrences of a given object (key) in the array (using compareTo()). public boolean is Sorted (Comparable[] a); Returns whether the array is sorted in ascending order 2. public class Find t extends Comparable>; this means the methods will take arrays with elements of type T, there's no need to cast the argument, and the compiler will generate no warning. public T getLargest (T[] a); Returns the largest object in the array public boolean is present (T[] a, T key); Returns whether a given object (key) is present in the array (using compareTo()) public int presentNTimes (T[] a, T key); A count of the number of occurrences of a given object (key) in the array (using compareTo()). public boolean is Sorted (T[] a); Returns whether the array is sorted in ascending order Create a driver program Test3 that uses the same objects as in Test2 as well as the following object to search and count: new Square (4); Note: you can ignore the warning about "unchecked or unsafe operations when you compile Find.java. B. To illustrate how general the methods in Find.java are, create a Cat class (instance variables: name and weight) that implements Comparable. Compare cats based on name first, and if the names are the same, compare them using weight. Create a driver program Test4 that uses two arrays of 3 cats, one sorted in ascending order and one unsorted, as well as a cat to search and count, to test the methods in Find.java. e. Source code for Find f. The test driver program Test3 g. The output of Test3 h. Source code for Cat i i. The test driver program Test4 j. The output of Test4 2. Interfaces and Polymorphism: A. Implement the Comparable interface for the various shapes where the compareTo() method uses the value of perimeter/area as the basis for comparison. Implement in Find.java the following methods using one of the following two ways to handle generic types: 1. As in the textbook (see the Sorting class in Chapter 10): public class Find; This means the methods will take Comparable arrays and array elements may need to be cast to T (see examples in Chapter 10). Note: this approach will generate a warning about "unchecked or unsafe operations when you compile Find.java, which can be ignored. public Comparable getLargest (Comparable[] a); Returns the largest object in the array public boolean is Present (Comparable[] a, T key); Returns whether a given object (key) is present in the array (using compareTo()) public int presentNTimes (Comparable[] a, T key); A count of the number of occurrences of a given object (key) in the array (using compareTo()). public boolean is Sorted (Comparable[] a); Returns whether the array is sorted in ascending order 2. public class Find t extends Comparable>; this means the methods will take arrays with elements of type T, there's no need to cast the argument, and the compiler will generate no warning. public T getLargest (T[] a); Returns the largest object in the array public boolean is present (T[] a, T key); Returns whether a given object (key) is present in the array (using compareTo()) public int presentNTimes (T[] a, T key); A count of the number of occurrences of a given object (key) in the array (using compareTo()). public boolean is Sorted (T[] a); Returns whether the array is sorted in ascending order Create a driver program Test3 that uses the same objects as in Test2 as well as the following object to search and count: new Square (4); Note: you can ignore the warning about "unchecked or unsafe operations when you compile Find.java. B. To illustrate how general the methods in Find.java are, create a Cat class (instance variables: name and weight) that implements Comparable. Compare cats based on name first, and if the names are the same, compare them using weight. Create a driver program Test4 that uses two arrays of 3 cats, one sorted in ascending order and one unsorted, as well as a cat to search and count, to test the methods in Find.java. e. Source code for Find f. The test driver program Test3 g. The output of Test3 h. Source code for Cat i i. The test driver program Test4 j. The output of Test4