Triangle program The lengths of sides a, b,and c are double precision and expect
ID: 3686630 • Letter: T
Question
Triangle program
The lengths of sides a, b,and c are double precision and expected to be greater than zero. However, the user might supply bad data Accept whatever values the user provides. The lengths are not in any particUlar order (don't assume that a is the smallest or largest.) Include the following methods that return Boolean values including if the particular property holds. Give your methods exactly these names Three sides make a triangle if the sum of two sides s greater than the third side. This must be true for all three combinations of sides. For the other "is" methods, immediately return false if the sides do not make up a legitimate triangle Use isTriangle() to test this. Otherwise, continue testing the relevant property. Use the Pythagorean Theorem to determine if a triangle a a right triangle. A triangle is isosceles 4 two or three sides are the same length. (Sometimes isosceles is taken to mean two sides the same and the third different) Also include a method area() which calculates and returns the area of the triangle (as a double precision value). Return -1 if the object is not a triangle. Include a costring () method that returns a string based on the object: Use Blue J to develop and test your class. For this project there will be no min method There will be no System.out.print () statements since all user interaction will be through BlueJ. After your source Me compiles, you will be able (in BlueJ) to click on the rectangle that represents the class to instantiale it. Now a red rectangle should appear that represents an object. Clicking and selecting methods of the object should now work. Instantiate several Triangle with various sides and verify that your class works correctly. Write a class called Triangle that represents a triangle. It has three double precision instance variables representing the three sides. Write a constructor (or Triangle objects that takes three double precision values public Triangle(double a, double b, double c)Explanation / Answer
I have no access to BlueJ so, written a normal program. Please modify it accordingly by replacing println statements with reuiqed
import java.util.*;
import java.lang.*;
class Triangle
{
double a=0.0,b=0.0,c=0.0;
Triangle(double a,double b,double c)
{
this.a=a;
this.b=b;
this.c=c;
}
public boolean isIsosceles()
{
if(isTriangle())
if(a==b|| a==c || b==c)
return true;
return false;
}
public boolean isScalene()
{
if(isTriangle())
if(a!=b && b!=c && a!=c)
return true;
return false;
}
public boolean isEquivalateral()
{
if(isTriangle())
if(a==b && b==c)
return true;
return false;
}
public boolean isRight()
{
if(isTriangle())
if((Math.pow(a,2)==Math.pow(b,2)+Math.pow(c,2)) || (Math.pow(b,2)==Math.pow(a,2)+Math.pow(c,2)) || (Math.pow(c,2)==Math.pow(b,2)+Math.pow(a,2)))
return true;
return false;
}
public boolean isTriangle()
{
if(a>0 && b>0 && c>0)
return true;
else
{
System.out.println("these sides don't form a triangle");
System.exit(0);
}
return false;
}
public double Area()
{
if(isTriangle())
{
double s=(a+b+c)/2;
return Math.sqrt((s*(s-a)*(s-b)*(s-c)));
}
else return -1;
}
public String toString()
{
return "Sides of a triangle: "+ a +" "+b +" "+c;
}
}
public class HelloWorld{
public static void main(String []args){
Scanner read=new Scanner(System.in);
System.out.println("Enter sides of a triangle");
double a=read.nextDouble();
double b=read.nextDouble();
double c=read.nextDouble();
Triangle test=new Triangle(a,b,c);
if(test.isScalene())
System.out.println("Triangle is scalene");
else
System.out.println("Triangle is not scalene");
if(test.isRight())
System.out.println("Triangle is right angle");
else
System.out.println("Triangle is not right angle");
if(test.isEquivalateral())
System.out.println("Triangle is equivaletral");
else
System.out.println("Triangle is not equivalateral");
if(test.isIsosceles())
System.out.println("Triangle is isosceles");
else
System.out.println("Triangle is not isosceles");
System.out.println("Area :"+ test.Area());
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.