Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Beginner Java Programming //Triangle.java from Lab 2 public class Triangle extends GeometricObject { //A no-arg constructor public Triangle() { super(); side1 = 0.0; side2 =

Beginner Java Programming

image text in transcribed

//Triangle.java from Lab 2

public class Triangle extends GeometricObject { //A no-arg constructor public Triangle() { super(); side1 = 0.0; side2 = 0.0; side3 = 0.0; } //set methods to default value of 1.00 double side1 = 1.0; double side2 = 1.0; double side3 = 1.0; //constructor that creates a rectangle with the specified sides public Triangle(double a, double b, double c, String color, boolean filled) { super(color, filled); side1 = a; side2 = b; side3 = c; } //getter & setter methods for data public double getSide1() { return side1; }

public void setSide1(double side1) { this.side1 = side1; }

public double getSide2() { return side2; } public void setSide2(double side2) { this.side2 = side2; } public double getSide3() { return side3; } public void setSide3(double side3) { this.side3 = side3; } public void show() { System.out.println(side1+","+side2+","+side3+","); } //method to calculate area public double getArea(){ double s=(side1+side2+side3)/2; double area=s*(s-side1)*(s-side2)*(s-side3); return area; } //method to calculate perimeter public double getPerimeter(){ return (side1 + side2 + side3); } //toString method public String toString(){ return "Triangle: side1 = " + side1 + " side2 = " + side2 + " side3 = " + side3 +" "+ super.toString(); } }

//GeometricObject.java, don't know if you need this but triangle class extends to this class

public class GeometricObject { private String color; private boolean filled; public GeometricObject() { color = "green"; filled = true; } public GeometricObject(String color, boolean filled) { this.color = color; this.filled = filled; } //Getter & Setter color method public String getColor() { return color; } public void setColor(String color) { this.color = color; } //Getter method for filled (Since filled is boolean getter method name is isFilled) public boolean isFilled() { return filled; } //Setter filled method public void setFilled(boolean filled) { this.filled = filled; } //String representation of object public String toString() { return "Color: " + color + " and Filled: " + filled; } }

Make a copy of your Triangle class for Lab 2 and then make the following two modifications. First, add this requirements to the Triangle constructor : make sure that the sum of any two sides is greater than the third side. If not, throw an IllegalTriangle Exception. The constructor header can be like this: public Triangle (double sidel, double side2, doube side3) throws IllegalTriangleException Implement this requirement. Secondly, in your test program, prompt for each of the value sidel, side2 and side3 in a method and each time throw a InputMismatchException if the wrong data type is entered from the keyboard. Then also entered invalid values such that it will throw the IllegalTriangleException error as explained above

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Exadata

Authors: Martin Bach, Kristofferson Arao

2nd Edition

1430262427, 9781430262428

More Books

Students also viewed these Databases questions

Question

What is that?

Answered: 1 week ago