Question: hey guys, i am working with java program. so i did some sub and super classes and just start learning abstract classes. in this project
hey guys, i am working with java program. so i did some sub and super classes and just start learning abstract classes. in this project im building my program as given from UML diagram. i do have shape.java also Circle.java, Rectangle.java as well as main class ShapeClient.java. all those classes are working. but right now i am trying to add Triangle.java which will not calculate area but will print true or false if sides are equal or not so i am using isEquilateral method. i have Triangle.java and it compiles and it is abstract class. however when i am trying to use it in the ShapeClient.java i have error //ShapeClient.java:14: error: Triangle is abstract; cannot be instantiated Shape s3 = new Triangle("Triangle 3", 10, 10, 10);
so that is where i am stuck. i will put my classess what i have.
shape.java
public abstract class Shape { private String name;
public Shape(String name) { this.name = name; }
public abstract double getArea();
//public abstract boolean isEquilateral();
public String getName() { return name; } }
Circle.java
public class Circle extends Shape {
private double radius;
public Circle(String name, double radius) {
super(name);
this.radius = radius;
}
public double getArea() {
return Math.PI * radius * radius;
}
}
rectangle.java
public class Rectangle extends Shape {
private double width;
private double length;
public Rectangle(String name, double width, double length) {
super(name);
this.width = width;
this.length = length;
}
public double getArea() {
return width * length;
}
}
Triangle.java
public abstract class Triangle extends Shape{
private double size1;
private double size2;
private double size3;
public Triangle(String name, double size1,
double size2,double size3) {
super(name);
this.size1 = size1;
this.size1 = size2;
this.size1 = size3;
}
public boolean isEquilateral(){
if(size1==size2 & size2==size3){
}
return true;
}
}
ShapeClient //main program
import java.util.ArrayList;
public class ShapeClient
{
public static void main(String[] args) {
ArrayList
Shape s1 = new Circle("circle 1", 10);
shapeList.add(s1);
Shape s2 = new Rectangle("rectangle 2", 100, 100);
shapeList.add(s2);
Shape s3 = new Triangle("Triangle 3", 10, 10, 10);
shapeList.add(s3); //this is where i am stuck
System.out.println("triangle is isEquilateral");
if (!s1.getClass().isInstance(s2)) {
System.out.println("Actual types of s1 and s2 are different");
}
double totalArea = sumAreasOfShapes(shapeList);
System.out.println("The total area of the shapes are " + totalArea);
}
public static double sumAreasOfShapes(ArrayList
double sum = 0.;
// Use the for loop
for (int i=0; i sum += shapeList.get(i).getArea(); } return sum; } } need help to make program work Thanks. 
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
