Question: java programming Modified the Triangle class you created for lab #2. In a triangle, the sum of any two sides is greater than the other





Modified the Triangle class you created for lab \#2. In a triangle, the sum of any two sides is greater than the other side. 1. Define the IllegalTriangleException class that extends the Exception class. This class contains only two constructors: a no-arg constructor and a constructor which takes a string parameter. 2. Modify the second constructor of the Triangle class (The constructor creates a triangle with the specified side1, side2, and side3). In this constructor, if the three sides violate the rule| specified above, throw an IllegalTriangleException exception. Write a test program that does the following tasks: 1. Create a text file called sides.txt which contains three randomly generated integers between 1 and 10. 2. Input the three integers from the sides.txt file. 3. Write a try block. In the block, create a new Triangle object using the three integers. 4. Write a catch block to handle the IllegalTriangleException. In the block, print the message: "IllegaiTriangleException: The triangle cannot be created." private string color = "whit private boolean filled; private java.util. Date datecreated; I** Construct a default geometric object / public Geometricobject () I datecreated = new java, util. Date () ; 1 return filled: f Set a new filled */ public vold setFilled(boolean filled) I this.filled = filled; ) I"l cet ditecreated y public java. util. pate getbatecreated() I return datecreated; 1 1" peturn a strioy tegresentation of this object " I publie string tostring () 1 return "created on " + datecreated + "incolos: "+ color + " and tilled: " filled: public class Triangle eztends Geometricobject! private double sidel; private double side2; private double side3; publie Triangle () f sidel =0.0; side 2=0.0; side 3=0.0; 1 publie Triangle (double side1, double side2, double side3) I this. sidel = sidel: this. 51de2 = side2: thin.side3 = side3; public double getsidel() I return sidex: ) public void setsidel (double sidell it this.stdele sideli: public double getsidezi l return sidec: public void sotsideichotible thie.sidez- siont: public double getside3() I return side3; 1 publie void setside3 (double side3) I this. side 3= side 3 ; 1 public double getperimater() I return sidel+side 2+ side 3 ; 1 public string tostring() ( return super, tostring ()+ * First olde:" + this, sidel + *, second slde:" + this. side2+", Fhird side:* + this. side3; 1 public atatic void main (5tring(l args) I Scantet sides = new Scanner ( Systes, in) i Systea, out,printIn("encer the three sides of triasple")/ double al = Ades,nextint (i) double 57 - sides, nextint (1) : public static void main (String [] args) I Scannersides=newScanner(System.in); System. out.println("enter the three sides of triangle"); double si = sides.nextInt (1) : double s2 = sides,nextint (1); double s3= sides.nextint (); Triangle t= nev Triangle (s1,s2,53); String color = sides.next (); t.setColor (color); boolean boolvalue = sides, hastext ( ): t.setfilled(boolvalue); System, eat.println ("perineter of the triangle is + t.getferinete Systen. out.printin(t)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
