Question: java Write a program to define a generic shape and specific shapes such as a rectangle, a triangle, and a circle. Test each class with
java Write a program to define a generic shape and specific shapes such as a rectangle, a triangle, and a circle. Test each class
with its own driver before they can be used. Create a test class a helper for the driver to and a driver to test the entire
design.
You must complete the design diagram by including the designs of Shape, Rectangle, Circle, Triangle, and
InvalidTriangleException and the class relationships. The driver and the test class are for testing purpose only. Shape: An abstract class that defines a Shape object.
The Shape class will have one field:
name The name of this shape.
The Shape class will have the following methods.
Default constructor Creates a Shape instance with a default name.
The second constructor Given a name, creates a Shape instance with the name.
getName Retrieves the name of this shape.
setName Given a name, changes the name of this shape to the new name.
area Returns the area of this shape.
abstract method that will be implemented by the sub classes.
equals Compares this shape with some other object. This method overrides Java equals
method.
toString Represents this shape as a string literal. This method overrides Java toString
method.
Shape
Rectangle Circle Triangle
InvalidTriangleException The Triangle class will inherit all public methods except the constructors from the Shape class and have the following
methods:
Default constructor Creates a default triangle instance. By default, a triangle has the following values for
its fields:
name: Triangle
sideOne:
sideTwo:
sideThree:
The second constructor For example, new Triangle Right Triangle
If a triangle is created with sides that violate the rule, an
InvalidTriangleException object with a proper message should be thrown.
For example, and cant form a triangle.
getSideOne Returns the first side of this triangle.
setSideOne Given a side, changes the first side of this triangle if the new side will form a triangle
with the other two sides. Otherwise, an InvalidTriangleException object with a proper
message should be thrown. getSideTwo Returns the second side of this triangle.
setSideTwo Given a side, changes the side two of this triangle if the new side will form a triangle
with the other two sides. Otherwise, an InvalidTriangleException object with a proper
message should be thrown.
getSideThree Returns the third side of this triangle.
setSideThree Given a side, changes the side three of this triangle if the new side will form a triangle
with the other two sides. Otherwise, an InvalidTriangleException object with a proper
message should be thrown.
area Returns the area of this triangle. This method is originally written in Shape class. It is
implemented to return the area of this triangle.
Heron's formula states that the area of a triangle
equals Compares this triangle with some other object. This method overrides the equals
method from the Shape class.
toString Represents this triangle as a string literal. This method overrides the toString method
from the Shape class.
InvalidTriangleException:
Create class InvalidTriangelException as a sub class of java.lang.Exception class. In the class, create a nondefault
constructor that constructs a new exception with a specified message.
public class InvalidTriangleException extends Exception
public InvalidTriangleExceptionString message
Call super constructor with the parameter message.
This class is used to address an abnormal execution flow in Triangle class. In the second constructor and the setters for
the sides, include the codes that may throw exceptions in a try block, and then add exception handlers. For this project, catch and handle InvalidTriangleException and other exceptions where they
occur in Triangle class. The following shows one example that handles InvalidTriangleException. If three sides do not
construct a valid triangle, an InvalidTriangelException object is thrown explicitly and is caught in the first exception
Create a test class with three static methods shown below at minimum.
public class Test
public static void start
Create an empty list of shapes and save the reference.
Pass the reference to create method that fills the list.
Pass the reference to display method that prints the list.
The following can be added here or into an additional method.
Remove a shape.
Display the list again.
Check the size of the list.
public static returnTypeOrVoid createa reference to a list
Create shape objects using data from an input file.
Note: A shape can be a rectangle, a circle or a triangle.
Add the objects into the list.
public static returnTypeOrVoid displaya reference to a list
Display the objects of the list.
Create a driver program. In main of the driver program, call start to start the entire testing process.
public class Driver
publicstatic void mainString args
Test.start;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
