Question
java.netbeans please i need help on my assignment Problem Description This assignment is a hand-on Arrays and Array list. Given the following Point class. public
java.netbeans
please i need help on my assignment
Problem Description
This assignment is a hand-on Arrays and Array list. Given the following Point class.
public class Point { private double x,y; public Point(){} public Point(double x, double y){ setPoint(x,y);} public void setPoint(double x, double y){
this.x = x; this.y = y; }
public double getX(){ return this.x;} public double getY(){ return this.y;} public double distance(Point p){
return Math.sqrt( Math.pow(p.x-x,2)+ Math.pow(p.y-y,2)); }
public boolean isDifferent(Point p){ return this.x!=p.x || this.y !=p.y
}
public String toString (){ return "(" + x+ "," + y + ")"; } }
Q1. Define a class Assignment2 in which it has the main method as follows:
1- Define an array list of Points, call it pList
2- Add 10 random point objects (coordinates of each point is between [-10,10] ) to the
pList
3- Add the point (2,4) in the middle and at the beginning of pList
4- Add the point (5,6) just before the last occurrence of point (2,4).
(Hint: calculate the position of (2,4) using lstIndexOf and then add (5,6) before it.
5- Print the list and see if addition is correct.
6 -Print the centroid of pList (See method developed in Q2).
7- Print the centroid of all points that are laying in the first quadrant. (use methods
developed in Q2 and Q3).
8- Remove the last occurrence of the point (2,4).
9. Reverse the elements of pList.
Q2. Write a method that takes an array list of Points (lst) and calculates and returns the centroid point. Centroid point is calculated as follows:
X coordinate of centroid = average values of x-coordinates of all points in the list. Y coordinate of centroid = average values of y-coordinates of all points in the list.
Q3. Write a method that takes an array of Points (arr) and returns all points that are laying in the first quadrant.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started