Description
The following workshop lets you practice basic java coding techniques, creating classes, methods, using arrays, inheritance, polymorphism, Exceptional Handling. Task – 1: Design an abstract class named GeometricObject that contains: • A private String data field named color (default value “white”) • A private Boolean data field named filled. • A no-arg constructor. • A protected overloaded constructor GeometricObject(String color, boolean filled). • The accessor and mutator methods for color and filled. • An abstract method getArea() • An abstract method getPerimeter() Design another class named Triangle that contains: ❖ Triangle class must inherit the GeometricObject class. ❖ 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 side3. ❖ The accessor methods for all three data fields. ❖ A method named getArea() that returns the area of this triangle. ❖ A method named getPerimeter() that returns the perimeter of this triangle. ❖ A method named toString() that returns a string description for the triangle. ❖ The formulate to compute the area of the triangle is as follows: JAC – 444 Semester —— ➢ Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filled. ➢ The program should create a Triangle object with the given sides and set the color and filled properties using the input. ➢ The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not. Task – 2 Triangle class in Task – 1 (above), defines a triangle with three sides. In a triangle, the sum of any two sides is greater than the other side. The Triangle class must obey/ follow to this rule. Design a TriangleException class, and modify the constructor of the Triangle class to throw a TriangleException object if triangle is created with sides that violates the rule, as follow: /**Construct a triangle with the specified sides */ public Triangle(double s1, double s2, double s3) throws TriangleException{ //Implementation } Hint: For not having any confusion you can copy your Triangle class from the Task – 1 and rename it in Task – 2. Write a test program that will create two Triangle class objects one with legal sides and the other will Illegal side. Note: Students are encouraged to design their own outputs for the both the tasks. Continue to the next page… JAC – 444 Semester —— Workshop Header /********************************************** Workshop # Course: – Semester Last Name: First Name: ID: Section: