Professional Documents
Culture Documents
Patel Arth Lab3
Patel Arth Lab3
Here, First I created triangle class that define IllegalTriangleException class, that extends the
Exception class, and it contains two constructor. After that in class Triangle I modfied second
constructor.
Code:
public IllegalTriangleException()
{
super();
}
}
class Triangle
{
private int side1, side2, side3;
public Triangle()
{
side1 = 0;
side2 = 0;
side3 = 0;
}
//lets modified second costructor as given in the question
//second constructor
public Triangle(int side1, int side2, int side3) throws
IllegalTriangleException {
if (side1 + side2 > side3)
{
this.side1 = side1;
this.side2 = side2;
this.side3 = side3;
}
else
throw new IllegalTriangleException();
}
//TriangleTest.java
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
Methodology:
Here, First I created triangle class that define IllegalTriangleException class, that extends the
Exception class, and it contains two constructor. After that in class Triangle I modfied second
constructor. After that I created a test program that creates Sides.txt file. In this I use try and catch block
for handling IllegalTriangleException. In this program I made changes, that given in the question.