Thanks for the help The Shapes Package Code can be found her

Thanks for the help.

The Shapes Package Code can be found here: http://cs.stcc.edu/wp-content/uploads/2016/10/shapes.zip

Design and implement a class named Triangle that extends Shape. The class contains: . Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. . A no-arg constructor that creates a default triangle. .A constructor that creates a triangle with the specified side1, side2, and side;3 . A constructor that creates a triangle with the specified side1, side2, side3, as well as color and filled properties. . The accessor methods for all three data fields. . A method named getArea() that returns the area of this triangle. Use . A method named getPerimeter) that returns the perimeter of this . A method named toString) that returns a string description for the Heron\'s Formula to compute the area. triangle. triangle. This method should return something likeTriangle: side1 - 10, Side2 = 5, side3 = 7 Make sure that when bad triangle sides are used to construct the triangle that the appropriate error message(s) are given. Use the TestShapes class in the z class. ip file Shapes Package Code to test your

Solution

/**
* The java program Triangle that sets the sides of a triangle.
* The class contains methods to area and perimter of the triangle.
* */
//Triangle.java
package shapes;
public class Triangle extends Shape
{

   private double side1;
   private double side2;
   private double side3;

   public Triangle() {

       side1=0;
       side2=0;
       side3=0;      
   }

   public Triangle(double side1,double side2,double side3) throws InvalidTriangleSides {

       if(side1<0 || side2<0 || side3<0)
           throw new InvalidTriangleSides(\"Invalid side lengths\");
      
       this.side1=side1;
       this.side2=side2;
       this.side3=side3;      
   }
   public Triangle(double side1,double side2,double side3,String color, boolean filled) throws InvalidTriangleSides {

       super(color, filled);
       if(side1<0 || side2<0 || side3<0)
           throw new InvalidTriangleSides(\"Invalid side lengths\");
       this.side1=side1;
       this.side2=side2;
       this.side3=side3;      
   }

   public double getSide1(){      
       return side1;
   }
   public double getSide2(){      
       return side2;
   }
   public double getSide3(){      
       return side2;
   }

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

   /** Return color */
   public String getColor() {
       return color;
   }
  
   public double getArea() {      
       double s=getPerimeter();      
       return Math.sqrt(s*(s-side1)*(s-side2)*(s-side3));
   }

   public double getPerimeter() {
       return (side1+side2+side3)/2.0;
   }
  
   @Override
   public String toString() {      
       return \"side1 = \"+side1
               +\" side2 = \"+side2
               +\" side3 = \"+side3;
   }

}

------------------------------------------------------------------------------------------------------------


//InvalidTriangleSides.java
package shapes;
public class InvalidTriangleSides extends Exception {

   public InvalidTriangleSides(String msg) {
       super(msg);
   }
  
}

------------------------------------------------------------------------------------------------------------


/**
* The java program TestShapes that tests the
* Triangle class and calls the methods
* of triangle and print sides, perimter and
* area
* */
//TestShapes.java
package shapes;
public class TestShapes {
public static void main(String[] args) throws InvalidTriangleSides {
  
   //Create a instance of shape object for Triangle
    Shape s3 = new Triangle(10, 8, 3);
    System.out.println(\"\ A triangle \" + s3);
    System.out.println(\"The color is \" + s3.getColor());
    System.out.println(\"The area is \" + s3.getArea());
    System.out.println(\"The perimeter is \" + s3.getPerimeter());
  
//Create a instance of Triangle class
    Triangle tri = (Triangle)s3;
    System.out.println(\"Side 1 is \" + tri.getSide1());
    System.out.println(\"Side 2 is \" + tri.getSide2());
    System.out.println(\"Side 3 is \" + tri.getSide3());   
}
}

------------------------------------------------------------------------------------------------------------

Sample Output:


A triangle side1 = 10.0 side2 = 8.0 side3 = 3.0
The color is white
The area is 9.921567416492215
The perimeter is 10.5
Side 1 is 10.0
Side 2 is 8.0
Side 3 is 8.0

Thanks for the help. The Shapes Package Code can be found here: http://cs.stcc.edu/wp-content/uploads/2016/10/shapes.zip Design and implement a class named Tria
Thanks for the help. The Shapes Package Code can be found here: http://cs.stcc.edu/wp-content/uploads/2016/10/shapes.zip Design and implement a class named Tria
Thanks for the help. The Shapes Package Code can be found here: http://cs.stcc.edu/wp-content/uploads/2016/10/shapes.zip Design and implement a class named Tria

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site