In: Computer Science
in Java:
A point in the x - y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x - y plane. You should then perform operations on a point, such as :
– Print the point
– Set the x-coordinate
– Set the y-coordinate
– Get the x-coordinate
– Get the y-coordinate
– Add() : add two points
– Sub(): subtract two points
– Mul(): multiply two points
– Div(): divide one point from the other
– Ass(): assign one point to the other
– Equ(): check if two points are equal
– LessThan(): check if one point is less than the other • Note: R = √ X2 − Y2
– The default constructor
– The second constructor
– The copy constructor 2.
## Design a class pointTypeTest to test the design of pointType.
Thank you in advance!
Note: I browsed the net for how to check whether one point is less than another.But i didnt found.Could u plz provide how to compare two points.So that I can convert it to java logic.Thank u
__________________
pointType.java
public class pointType {
//Declaring instance variables
private double x;
private double y;
//Zero argumented constructor
public pointType() {
this.x = 0;
this.y = 0;
}
//Parameterized constructor
public pointType(double x, double y) {
this.x = x;
this.y = y;
}
//Creating Copy Constructor
public pointType(pointType pt) {
this.x = pt.x;
this.y = pt.y;
}
// getters and setters
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
//toString method is used to display the contents
of an object inside it
@Override
public String toString() {
return "(" + x + "," + y +
")";
}
//Method will add two points
pointType add(pointType other)
{
pointType p=new
pointType(this.x+other.getX(),this.y+other.getY());
return p;
}
//Method will subtract two points
pointType sub(pointType other)
{
pointType p=new
pointType(this.x-other.getX(),this.y-other.getY());
return p;
}
//Method will multiply two points
pointType mul(pointType other)
{
pointType p=new
pointType(this.x*other.getX(),this.y*other.getY());
return p;
}
//Method will divide two points
pointType div(pointType other)
{
pointType p=new
pointType(this.x/other.getX(),this.y/other.getY());
return p;
}
//Method will assign one point to another
void ass(pointType other)
{
this.x=other.getX();
this.y=other.getY();
}
//Method will check whether the two points are same or
not
boolean equ(pointType other)
{
if(this.x==other.getX() &&
this.y==other.getY())
return true;
else
return false;
}
}
___________________
pointTypeTest.java
public class pointTypeTest {
public static void main(String[] args) {
pointType p1 = new pointType(4,
6);
pointType p2 = new
pointType(3,4);
System.out.println("Displaying
Point#1:" + p1);
System.out.println("Displaying
Point#2:" + p2);
System.out.println("After adding
Point#1 and Point#2:" + (p1.add(p2)));
System.out.println("After
subtracting Point#2 from Point#1:" + (p1.sub(p2)));
System.out.println("After
multiplying Point#1 and Point#2:" + (p1.mul(p2)));
System.out.println("After dividing
Point#1 with Point#2:" + (p1.div(p2)));
System.out.println("Checking
whether the Point#1 and Point#2 are equal or not :"
+p1.equ(p2));
}
}
____________________________
Output:
Displaying Point#1:(4.0,6.0)
Displaying Point#2:(3.0,4.0)
After adding Point#1 and Point#2:(7.0,10.0)
After subtracting Point#2 from Point#1:(1.0,2.0)
After multiplying Point#1 and Point#2:(12.0,24.0)
After dividing Point#1 with Point#2:(1.3333333333333333,1.5)
Checking whether the Point#1 and Point#2 are equal or not
:false
____________Thank You