Whether you face any problem or need any modification
then share with me in the comment section, I'll happy to help
you.
import java.util.ArrayList;
//Polygon class
public abstract class Polygon implements Drawable
{
//private instance variable
private ArrayList<Point> points;
private String colour;
/* Creates a Polygon with colour and ArrayList of
Points */
public Polygon(String colour)
{
this.colour = colour;
points = new
ArrayList<>();
}
/* method returns the points */
public ArrayList<Point> getPoints()
{
return points;
}
/* method to add a Point p to the points list */
public void addPoint(Point p)
{
points.add(p);
}
@Override
public boolean equals(Object other)
{
//if both objects are the
same
if(this == other)
return
true;
//if other is not a Polygon they
cannot be equal
if(!(other instanceof
Polygon))
return
false;
//convert to Polygon
Polygon poly =
(Polygon)other;
//if colour is not equals to this
Polygon
if(!colour.equals(poly.colour))
return
false;
//if number of Points is not equals
to this Polygon
if(points.size() !=
poly.points.size())
return
false;
//check for all the Points in
list
for(int i=0; i<points.size();
i++)
{
//if Point is
not equal
if(points.get(i)
!= poly.points.get(i))
return false;
}
//return true if both objects are
the same
return true;
}
//abstract method to return area of the Polygon
public abstract double getArea();
}
In Pl you will create an interface, Drawable, and an abstract class Polygon. The Point class...
Susceptible.java interface Susceptible { public boolean infect(Disease disease); public void forceInfection(Disease disease); public Disease getCurrentDisease(); public void setImmune(); public boolean isImmune(); public Point getPosition(); } Movable.java interface Movable { public void move(int step); } public class Point { private int xCoordinate; private int yCoordinate; /** * Creates a point at the origin (0,0) and colour set to black */ public Point(){ xCoordinate = 0; yCoordinate = 0; } /** * Creates a new point at a given coordinate and colour...
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...
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...
// ====== 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...
"Polygon Drawer Write an applet that lets the user click on six points. After the sixth point is clicked, the applet should draw a polygon with a vertex at each point the user clicked." import java.awt.*; import java.awt.event.MouseListener; import java.awt.event.MouseEvent; import java.applet.*; public class PolygonDrawer extends Applet implements MouseListener{ //Declares variables private int[] X, Y; private int ptCT; private final static Color polygonColor = Color.BLUE; //Color stuff public void init() { setBackground(Color.BLACK); addMouseListener(this); X = new int [450]; Y =...
Can you tell me if this is right please import java.lang.reflect.AnnotatedArrayType; /** * The class <b>Point</b> is a simple helper class that stares a 2 dimentional element on a grid * * @author Guy-Vincent Jourdan, University of Ottawa */ public class Point { public int dot, row, col; // ADD YOUR INSTANCE VARIABLES HERE /** * Constructor * * @param x * the x coordinate * @param y * the y coordinate...
(JAVA NetBeans) Write programs in java Example 10.21-24 //Animal.java /** Animal class * Anderson. Franceschi */ import java.awt.Graphics; public abstract class Animal { private int x; // x position private int y; // y position private String ID; // animal ID /** default constructor * Sets ID to empty String */ public Animal( ) { ID = ""; } /** Constructor * @param rID Animal ID * @param rX x position * @param rY y position */ public Animal( String...
COVERT TO PSEUDOCODE /****************************Vacation.java*****************************/ public abstract class Vacation { /* * private data field */ private double cost; private double budget; private String destination; /** * * @param cost * @param budget * @param destination */ public Vacation(double cost, double budget, String destination) { super(); this.cost = cost; this.budget = budget; this.destination = destination; } //getter and...
Must be in Java. Show proper reasoning with step by step process. Comment on the code please and show proper indentation. Use simplicity. Must match the exact Output. CODE GIVEN: LineSegment.java LineSegmentTest.java Point.java public class Point { private double x, y; // x and y coordinates of point /** * Creates an instance of Point with the provided coordinates * @param inX the x coordinate * @param inY the y coordinate */ public Point (double inX, double inY) { this.x...
Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade * */ public class Employee { private int empId; private String empName; private Vehicle vehicle; public Double calculatePay() { return null; } /** * @return the empId */ public int getEmpId() { return empId; } /** * @param empId * the empId to set */ public void setEmpId(int empId) { this.empId = empId; } /** * @return the empName */ public String getEmpName() { return...