(Need to complete the methods and pass a Junit test i can email them to you.)
public class Triangle implements Comparable {
/**
* Stores the number of objects instantiated from the
{@code Triangle} class
*/
private static int numTriangles;
/**
* The shortest side of the triangle
*/
private final double a;
/**
* The side of medium length of the triangle
*/
private final double b;
/**
* The longest side of the triangle
*/
private final double c;
/**
* Initializes the new {@link Triangle} object using
the provided sides in the
* arguments. The new triangle will have its shortest
side stored in the
* variable {@code a}, the medium length side stored in
the variable {@code b},
* and the longest side stored in the variable {@code
c}.
*
*
* Before initializing the triangle object, this
constructor verifies that the
* provided sides are positive and valid as triangle
sides otherwise it throws
* {@link IllegalArgumentException}. Verifying that the
three sides can form a
* valid triangle is to be delegated to {@link
Triangle#isValid} method.
*
*
* This constructor also increments the static
variable
* {@link Triangle#numTriangles} which tracks the
number of Triangle objects
* created.
*
* @param side1
* the first side of this triangle
* @param side2
* the second side of this triangle
* @param side3
* the third side of this triangle
*
* @throws IllegalArgumentException
* if the sides are not positive or the provided sides
cannot form a
* valid triangle
*/
public Triangle(double side1, double side2, double
side3) {
}
/**
* A {@code Triangle} is considered valid if and only
if the sum of two sides be
* greater than the third side. This condition has to
be true for all three
* combinations of the sides.
*
*
* Example 1: valid triangle
* Assume you have a triangle that has the following
sides {@code side1} =
* {@code 5}, {@code side2} = {@code 10}, and {@code
side3} = {@code 7}
* then:
* 5 + 10 greater than 7 (true), 5 + 7 greater than 10
(true), and
* 10 + 7 greater than 5 (true)
*
*
*
* Example 2: invalid triangle
* Assume you have a triangle that has the following
sides {@code side1} =
* {@code 1}, {@code side2} = {@code 2}, and {@code
side3} = {@code 7} then:
* 1 + 2 greater than 7 (false). Then this is not a
valid triangle
*
*
*
* @param side1
* the first side of this triangle
* @param side2
* the second side of this triangle
* @param side3
* the third side of this triangle
* @return true if this is a valid triangle
*/
public static boolean isValid(double side1, double
side2, double side3) {
}
/**
* Method to check if a triangle is equilateral
triangle by having equal length
* sides.
*
* @return {@code true} if the triangle is equilateral
otherwise {@code false}
*/
public boolean isEquilateral() {
}
/**
* Accessor method that returns the smallest side of
this triangle.
*
* @return the side {@code a} of the triangle. This
must be the smallest side.
*/
public double getA() {
}
/**
* Accessor method that returns the medium side of this
triangle.
*
* @return the side {@code b} of the triangle. This
must be the medium length
* side.
*/
public double getB() {
}
/**
* Accessor method that returns the longest side of
this triangle.
*
* @return the side {@code c} of the triangle. This
must be the longest side.
*/
public double getC() {
}
/**
* This method returns the perimeter of the triangle.
The perimeter of a
* triangle is the sum of all its sides.
*
* @return the perimeter of the triangle
*/
public double getPerimeter() {
}
/**
* This method returns the area of the triangle. The
area of a triangle given
* its sides {@code a}, {@code b}, and {@code c} is
$$sqrt(s * (s - a) * (s - b)
* * (s - c))$$ where $s$ is half the perimeter
(semiperimeter).
*
* @return the area of the triangle
*/
public double getArea() {
}
/**
* This method returns the number of objects
instantiated from the
* {@code Triangle} class.
*
* @return the number of {@code Triangle}
objects.
*/
public static int getNumTriangles() {
}
/**
* Compares area of this triangle object and the other
triangle {@code t}.
*
* @param t
* the other triangle
* @return the value {@code -1 } if the area of this
triangle is less than the
* argument's triangle area; {@code +1} if the area of
this triangle is
* greater than the argument's; and {@code 0} if this
area of this
* triangle is equal to the argument's within the
specified tolerance
* {@link ShapeUtil#TOL}.
*
* @throws IllegalArgumentException
* if the argument is null
*/
@Override
public int compareTo(Triangle t) {
}
/**
* Generates a hashCode of this triangle using its
sides length. Use Eclipse to
* generate this method for you.
*
* @return some hashCode
*/
@Override
public int hashCode() {
}
/**
* Compares this triangle with the argument {@code obj}
of Object type. This
* method overrides the base method defined in the root
class Object.
*
* Two triangles are equal if the difference between
the sides of the first
* triangle and the sides of second triangle is within
the allowed tolerance
* specified in {@link ShapeUtil#TOL}
*
*
* @return {@code true} if the triangle is equal to the
argument triangle within
* the tolerance specified in {@link
ShapeUtil#TOL}.
*/
@Override
public boolean equals(Object obj) {
return true;
}
@Override
public String toString() {
return "Triangle [" + a + ", " + b
+ ", " + c + "]";
}
}
import java.util.Objects;
public class Triangle implements Comparable {
/**
* Stores the number of objects instantiated from the {@code Triangle} class
*/
private static int numTriangles;
/**
* The shortest side of the triangle
*/
private final double a;
/**
* The side of medium length of the triangle
*/
private final double b;
/**
* The longest side of the triangle
*/
private final double c;
/**
* Initializes the new {@link Triangle} object using the provided sides in the
* arguments. The new triangle will have its shortest side stored in the
* variable {@code a}, the medium length side stored in the variable {@code b},
* and the longest side stored in the variable {@code c}.
* <p>
* <p>
* <p>
* Before initializing the triangle object, this constructor verifies that the
* provided sides are positive and valid as triangle sides otherwise it throws
* {@link IllegalArgumentException}. Verifying that the three sides can form a
* valid triangle is to be delegated to {@link Triangle#isValid} method.
* <p>
* <p>
* <p>
* <p>
* This constructor also increments the static variable
* {@link Triangle#numTriangles} which tracks the number of Triangle objects
* created.
*
* @param side1 the first side of this triangle
* @param side2 the second side of this triangle
* @param side3 the third side of this triangle
* @throws IllegalArgumentException if the sides are not positive or the provided sides cannot form a
* valid triangle
*/
public Triangle(double side1, double side2, double side3) {
if (isValid(side1, side2, side3)) {
if (side1 > side2 && side1 > side3) {
c = side1;
if (side2 > side3) {
b = side2;
a = side3;
} else {
b = side3;
a = side2;
}
} else if (side2 > side1 && side2 > side3) {
c = side2;
if (side1 > side3) {
b = side1;
a = side3;
} else {
b = side3;
a = side1;
}
} else {
c = side3;
if (side2 > side1) {
b = side2;
a = side1;
} else {
b = side1;
a = side2;
}
}
numTriangles += 1;
} else {
throw new IllegalArgumentException("Sides cannot form a triangle");
}
}
/**
* A {@code Triangle} is considered valid if and only if the sum of two sides be
* greater than the third side. This condition has to be true for all three
* combinations of the sides.
* <p>
* <p>
* <p>
* <p>
* Example 1: valid triangle
* <p>
* Assume you have a triangle that has the following sides {@code side1} =
* {@code 5}, {@code side2} = {@code 10}, and {@code side3} = {@code 7}
* then:
* <p>
* 5 + 10 greater than 7 (true), 5 + 7 greater than 10 (true), and
* 10 + 7 greater than 5 (true)
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* <p>
* Example 2: invalid triangle
* <p>
* Assume you have a triangle that has the following sides {@code side1} =
* {@code 1}, {@code side2} = {@code 2}, and {@code side3} = {@code 7} then:
* <p>
* 1 + 2 greater than 7 (false). Then this is not a valid triangle
*
* @param side1 the first side of this triangle
* @param side2 the second side of this triangle
* @param side3 the third side of this triangle
* @return true if this is a valid triangle
*/
public static boolean isValid(double side1, double side2, double side3) {
if (side1 <= 0 || side2 <= 0 || side3 <= 0) return false;
else if ((side1 + side2) <= side3) return false;
else if ((side1 + side3) <= side2) return false;
else if ((side2 + side3) <= side1) return false;
else return true;
}
/**
* Method to check if a triangle is equilateral triangle by having equal length
* sides.
*
* @return {@code true} if the triangle is equilateral otherwise {@code false}
*/
public boolean isEquilateral() {
return (a == b && b == c);
}
/**
* Accessor method that returns the smallest side of this triangle.
*
* @return the side {@code a} of the triangle. This must be the smallest side.
*/
public double getA() {
return a;
}
/**
* Accessor method that returns the medium side of this triangle.
*
* @return the side {@code b} of the triangle. This must be the medium length
* side.
*/
public double getB() {
return b;
}
/**
* Accessor method that returns the longest side of this triangle.
*
* @return the side {@code c} of the triangle. This must be the longest side.
*/
public double getC() {
return c;
}
/**
* This method returns the perimeter of the triangle. The perimeter of a
* triangle is the sum of all its sides.
*
* @return the perimeter of the triangle
*/
public double getPerimeter() {
return a + b + c;
}
/**
* This method returns the area of the triangle. The area of a triangle given
* its sides {@code a}, {@code b}, and {@code c} is $$sqrt(s * (s - a) * (s - b)
* * (s - c))$$ where $s$ is half the perimeter (semiperimeter).
*
* @return the area of the triangle
*/
public double getArea() {
double s = (a + b + c) / 2;
return Math.sqrt(s * (s - a) * (s - b) * (s - c));
}
/**
* This method returns the number of objects instantiated from the
* {@code Triangle} class.
*
* @return the number of {@code Triangle} objects.
*/
public static int getNumTriangles() {
return numTriangles;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Triangle triangle = (Triangle) o;
return Double.compare(triangle.a, a) == 0 &&
Double.compare(triangle.b, b) == 0 &&
Double.compare(triangle.c, c) == 0;
}
@Override
public int hashCode() {
return Objects.hash(a, b, c);
}
@Override
public String toString() {
return "Triangle [" + a + ", " + b + ", " + c + "]";
}
@Override
public int compareTo(Object o) {
return (int) (getArea() - ((Triangle)o).getArea());
}
}
(Need to complete the methods and pass a Junit test i can email them to you.)...
Why is my program returning 0 for the area of a triangle? public class GeometricObjects { private String color = " white "; private boolean filled; private java.util.Date dateCreated; public GeometricObjects() { dateCreated = new java.util.Date(); } public GeometricObjects(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public String getColor() { return color; } public void setColor(String color)...
Objective Extend the class GeometicShapes to include a Triangle class.. Background Reading ZyBooks Chapter 10 Task Create the following fields and methods for a Triangle class that extends the provided GeometricShapes class public class GeometricShapes { private String color = "red"; private boolean filled; private java.util.Date dateCreated; public GeometricShapes() { dateCreated = new java.util.Date(); } public GeometricShapes(String color, boolean filled) { dateCreated = new java.util.Date(); this.color = color; this.filled = filled; } public void setColor (String color)...
Triangle stuff. Write a function IsValid(side1, side2, side3) that takes as argument 3 positive integers and returns True if the three sides can form a triangle, False otherwise. Write a function Perimeter(side1, side2, side3) that takes 3 sides of a triangle and returns the perimeter of the triangle. Remember to only calculate the perimeter of valid triangles that you determined through the IsValid function. Now use Heron’s formula to calculate the area of a triangle with sides side1, side2, side3....
(The Triangle class) Design a class named Triangle that extends the GeometricObject class. The Triangle class contains: - Three float data fields named side1, side2, and side3 to denote the three sides of the triangle. - A constructor that creates a triangle with the specified side1, side2, and side3 with default values 1.0. - The accessor methods for all three data fields. - A method named getArea() that returns the area of this triangle. - A method named getPerimeter() that...
Welcome to the Triangles program Enter length 1: 3 Enter length 2: 5 Enter length 3: 5 Enter the base: 5 Enter the height: 8 --------------------- The triangle is Isosceles since it has two equal length sides. Isosceles triangle also has two equal angles The area is: 20 The permimeter is: 13 Continue? (y/n): y Enter length 1: 10 Enter length 2: 10 Enter length 3: 10 Enter the base: 10 Enter the height: 7 --------------------- The triangle is Equilateral...
Please include comments in the program .The program must be able to be compiled.Design a class named Triangle that extends GeometricObject. This class contains:* Three double data fields named side1, side2, and side3 with default values 1.0 to denote the three sides of a 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...
this is what i have so far but it does not work. please help
thank you
Part 2: Perimeter of a Triangle Write a program named Triangle.java that asks for the lengths of the three sides of a triangle and computes the perimeter if the input is valid.The input is valid if the sum of every pair of two sides is greater than the remaining side. For example, the lengths 3, 4, and 5 define a valid triangle: 3 plus...
I am trying to write a Geometry.java program but Dr.Java is giving me errors and I dont know what I am doing wrong. import java.util.Scanner; /** This program demonstrates static methods */ public class Geometry { public static void main(String[] args) { int choice; // The user's choice double value = 0; // The method's return value char letter; // The user's Y or N decision double radius; // The radius of the circle double length; // The length of...
Must be in Python 3.6 (please have a screen shot on the
code)
ex 2.14 :
# Enter three points for a triangle
x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a
triangle: "))
# Compute the length of the three sides
side1 = ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) **
0.5
side2 = ((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 -...
Design a general class GeometricObject can be used to model all geometric objects. This class contains the properties color and filled and their appropriate get and set methods. Assume that this class also contains toString() methods. The toString() method returns a string representation of the object. Define the Triangle, Circle, and Rectangle classes that extend the GeometricObject class. The Triangle class inherits all accessible data fields and methods from the GeometricObject class.In addition, it has three double data fields named...