Create a UML diagram with 3 lines per class/interface including all constructors.
public class Point {
public double X, Y;
public Point()
{
this(0, 0);
}
public Point(double newX, double newY)
{
X = newX;
Y = newY;
}
public static double distance(Point A, Point B) {
return Math.sqrt(Math.pow(A.X-B.X, 2) + Math.pow(A.Y-B.Y,
2));
}
}
public interface Polygon {
public int getNumberOfSides();
public double getPerimeter();
public double getArea();
}
public abstract class Simple_polygon implements Polygon{
public Point vertices[];
public Simple_polygon(int n) {
if (n < 3) {
throw new IllegalArgumentException();
}
vertices = new Point[n];
}
public int getNumberOfSides() {
return vertices.length;
}
public boolean isEquilateral() {
double sideLength = -1;
for (int i = 1; i < vertices.length; i++) {
double side = vertices[i - 1].distance(vertices[i]);
if (sideLength == -1) {
sideLength = side;
} else if (side != sideLength) {
return false;
}
}
if (vertices[vertices.length - 1].distance(vertices[0]) !=
sideLength) {
return false;
}
return true;
}
}
public class Triangle extends Simple_polygon {
public Point[] vertices;
public Triangle(Point a, Point b, Point c) {
super();
vertices[0] = a;
vertices[1] = b;
vertices[2] = c;
}
public double getPerimeter() {
double side1 = vertices[0].distance(vertices[1]);
double side2 = vertices[1].distance(vertices[2]);
double side3 = vertices[2].distance(vertices[1]);
return side1 + side2 + side3;
}
public double getArea() {
double x1 = vertices[0].x;
double y1 = vertices[0].y;
double x2 = vertices[1].x;
double y2 = vertices[1].y;
double x3 = vertices[2].x;
double y3 = vertices[2].y;
double area = Math.abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3
* (y1 - y2)) / 2);
return area;
}
}
public class Quadrilateral extends Simple_polygon {
public Point[] vertices;
public Quadrilateral(Point a, Point b, Point c, Point d){
super();
vertices[0] = a;
vertices[1] = b;
vertices[2] = c;
vertices[3] = d;
}
public double getPerimeter() {
double side1 = vertices[0].distance(vertices[1]);
double side2 = vertices[1].distance(vertices[2]);
double side3 = vertices[2].distance(vertices[3]);
double side4 = vertices[3].distance(vertices[1]);
return side1 + side2 + side3 + side4;
}
public double getArea() {
double a = vertices[0].x;
double a2 = vertices[0].y;
double b = vertices[1].x;
double b2 = vertices[1].y;
double c = vertices[2].x;
double c2 = vertices[2].y;
double d = vertices[3].x;
double d2 = vertices[3].y;
double area = Math.abs(((a * (b2 - d2) + b * (d2 - a2) + d
* (a2 - b2)) / 2)) +
Math.abs(((b * (c2 - d2)) + (c * (d2 - b2)) +
(d * (b2 - c2))) / 2);
return area;
}
}
Create a UML diagram with 3 lines per class/interface including all constructors. public class Point {...
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)...
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...
In Pl you will create an interface, Drawable, and an abstract class Polygon. The Point class is provided. Briefly go over the JavaDocs comments to see what is available to you. «interface Drawable +printToConsole(): void Polygon - points : List<Point> - colour : String Point + Polygon(String colour) + getPoints(): List<Point> + addPoint(Point p): void + equals(Object other): boolean +getArea(): double • The Polygon constructor initializes the List to a List collection of your choosing • add Point: Adds a...
Design a class named Triangle that extends GeometricObject class. The class contains: Three double data fields named side1, side2, and side3 with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle with color = "blue", filled = true. A constructor that creates a triangle with the specified side1, side2, side3 and color = "blue", filled = true. The accessor functions for all three data fields, named getSide1(), getSide2(), getSide3(). A function...
// ====== FILE: Point.java ========= // package hw3; /** * A class to that models a 2D point. */ public class Point { private double x; private double y; /** * Construct the point (<code>x</code>, <code>y</code>). * @param x the <code>Point</code>'s x coordinate * @param y the <code>Point</code>'s y coordinate */ public Point(double x, double y) { this.x = x; this.y = y; } /** * Move the point to (<code>newX</code>, <code>newY</code>). * @param newX the new x coordinate for...
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...
Which of the following is true about interfaces: An interface can have only non abstract methods. All methods in an interface must be abstract. A class can only implement one interface. None of the items listed. Can not contain constants but can have variables. What is the rule for a super reference in a constructor? It must be in the parent class' constructor. You cannot use super in a constructor. It must be the last line of the constructor in...
(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;...
Java Help 2. Task: Create a client for the Point class. Be very thorough with your testing (including invalid input) and have output similar to the sample output below: ---After declaration, constructors invoked--- Using toString(): First point is (0, 0) Second point is (7, 13) Third point is (7, 15) Second point (7, 13) lines up vertically with third point (7, 15) Second point (7, 13) doesn't line up horizontally with third point (7, 15) Enter the x-coordinate for first...