Question: The program has to be programmed in java please and thank you . Here is the question and the classes will be given then the

The program has to be programmed in java please and thank you . Here is the question and the classes will be given then the instructions for the second part of the assignment thanks.

The program has to be programmed in java please and thank you

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 and the classes will be given then

the instructions for the second part of the assignment thanks. Shape class

Here are the questions at the end I would like them to be answered as well in order thanks.

public abstract class Shape{ public abstract double getArea(); public abstract double getPerimeter();

Please program all of this in java since it is given to you in java please and thank you.

1. Inheritance and Polymorphism: Use the given classes (Shape, EquilTriangle, Circle, Square) and the driver program Testi: A. Run the program using the given "hard-coded" data. What is the result of using the equals() method of the base Object class? How is it determining equality? Report the results. B. Write an equals() method for EquilTriangle, Circle and Square that determines equal based on the shape's area (What class should it go in?). Run the Testi program again and report the results. C. Create a Test2 driver class to hold the following shapes in an array, compare each shape against the others (only once) using your equals() method and report the results. new Circle (2); new Circle (2); new Circle (3); new Square (Math.PI); new EquilTriangle (2); 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. a. The answer to the question in 1A b. The modified source code for Shape C. The Test2 driver program d. The output of Test2 e. Source code for Find f. The test driver program Test3 g. The output of Test3 h. Source code for Cat i. The test driver program Test4 j. The output of Test4

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!