Question

In: Computer Science

in Java: A point in the x - y plane is represented by its x-coordinate and...

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!

Solutions

Expert Solution

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


Related Solutions

A Point Class Definition A two-dimensional point may be represented by an x- and y-coordinate. In...
A Point Class Definition A two-dimensional point may be represented by an x- and y-coordinate. In this problem, you will write a Point class which stores this information and provides useful methods to work with points. We have provided an __init__ definition for the Point class. You will note that this accepts two arguments, being the x- and y-coordinates of the point. We have also included a __repr__ method, which will provide a canonical string representation of the point. Make...
Define a structure Point. A point has an x- and a y-coordinate. Write a function double...
Define a structure Point. A point has an x- and a y-coordinate. Write a function double distance(Point a, Point b) that computes the distance from a to b. Write a program that reads the coordinates of the points, calls your function, and displays the result. IN C++ if possible please give //comments
Given the plot of y=f(x) below, find the plot of y=f−1(x). A coordinate plane has a...
Given the plot of y=f(x) below, find the plot of y=f−1(x). A coordinate plane has a horizontal x-axis labeled from negative 7 to 7 in increments of 1 and a vertical y-axis labeled from negative 7 to 7 in increments of 1. A curve starts at the point left-parenthesis negative 1 comma 0 right-parenthesis, rises at an increasing rate from left to right and passes through left-parenthesis 1 comma 1 right-parenthesis and left-parenthesis 4 comma 6 right-parenthesis. Select the correct...
Consider a two-dimensional ideal flow in the x-y plane (with radial coordinate r2 = x2 +...
Consider a two-dimensional ideal flow in the x-y plane (with radial coordinate r2 = x2 + y2). Given the velocity potentials of 1) a uniform flow, 2) a source φ = (q/2π) ln r, and 3) a dipole φ = −d · r/(2πr2): a) Using the principle of superposition, construct a linear combination of the ingredients above that gives the flow past an infinite cylinder. [10 points] b) Sketch the streamlines of the flow everywhere in space. [10 points]
Four metal spheres, each 1cm in diameter are arranged on an X-Y coordinate plane as follows:...
Four metal spheres, each 1cm in diameter are arranged on an X-Y coordinate plane as follows: Sphere 1 has a charge of +2 millicoulombs and is situated at coordinate (0,0) Sphere 2 has a charge of +3 millicoulombs and is situated at coordinate (0.-4 cm) Sphere 3 has a charge of -4 millicoulombs and is situated at coordinate (-3 cm,0) Find the resultant force in Newtons on a fourth sphere with a charge of +1 millicoulomb situated at coordinate (4...
Find the coordinates of the point (x, y, z) on the plane z = 4 x...
Find the coordinates of the point (x, y, z) on the plane z = 4 x + 1 y + 4 which is closest to the origin.
2. Assume that the sum is fixed at the point (0,0) in the x,y plane. The...
2. Assume that the sum is fixed at the point (0,0) in the x,y plane. The path of a comet around the un is given by the equation y = x2 - 0.5 in astronomical units. (One astronomical unit is the distance between the sun and the Earth). a. Use a graphing tool, such as Desmos, to graph the function. *I have done the part and got the graph* b. Find the coordinate of the point where the comet is...
find the x-coordinate of the point, correct to two decimal places, on the parabola y=3.08-x^2 at...
find the x-coordinate of the point, correct to two decimal places, on the parabola y=3.08-x^2 at which the tangent line cuts from the first quadrant the triangle with the smallest area.
The coordinates of a point P in the x-y plane are (2;3) meters. q1 = 10...
The coordinates of a point P in the x-y plane are (2;3) meters. q1 = 10 C load (1;0) , q2 = 20 C load (-1;0) is placed in the metre position. The electric flied formed by these charges at the P point, find your size and direction.
The tangent plane of   f (x, y)  =  4x2y − 5xy3 at the point (1,1) can...
The tangent plane of   f (x, y)  =  4x2y − 5xy3 at the point (1,1) can be expressed in the form z  =  ax + by + c. (a) What is the value of a? (b) What is the value of c?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT