SBL Assignment 2 Edited
SBL Assignment 2 Edited
CODE:
Triangle.java
public class Triangle extends GeometricObject
{
private double side1 = 1.0; private double side2
= 1.0; private double side3 = 1.0;
public Triangle() {
super();
}
TriangleException.java
public class TriangleException extends Exception
{
public TriangleException(String message) { super(message);
}}
Test program:
import java.util.Scanner;
public class Test { public static void
main(String[] args) { Scanner input = new
Scanner(System.in);
// Prompt user for three sides of the triangle
System.out.print("Enter side1 of the triangle: "); double
side1 = input.nextDouble();
System.out.print("Enter side2 of the triangle: ");
double side2 = input.nextDouble();
System.out.print("Enter side3 of the triangle: ");
double side3 = input.nextDouble();
// Prompt for color and filled properties
System.out.print("Enter the color of the triangle: ");
String color = input.next();
System.out.print("Is the triangle filled (true/false): ");
boolean filled = input.nextBoolean();
input.close();
}}
OUTPUT:
Enter side1 of the triangle: 3
Enter side2 of the triangle: 4
Enter side3 of the triangle: 5
Enter the color of the triangle: green
Is the triangle filled (true/false): true
Triangle details:
Area: 6.0
Perimeter: 12.0
Color: green
Filled: true
Triangle: side1 = 3.0 side2 = 4.0 side3 = 5.0
Trying to create an invalid triangle:
Error: The sides do not form a valid triangle.