Hi,
Thank you for the opportunity to help you with your assignment.
The following is the code for your requirements as in the
instructions.
I have added comments in the code for your reference.
I have made sure to include all that is necessary for you to complete this assignment.
In case, if something is missing, drop me a comment.
If you have any queries, need changes in the code or need help
in following the code, leave me a comment.
I will reply within reasonable time.
If this answer helps you with your assignment, do upvote
it.
Your vote will motivate me to work better.
Here is the code.
//File: Point.java
public class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public double distance(Point other) {
double dx = this.x-other.x;
double dy = this.y-other.y;
double dist = Math.sqrt(dx*dx + dy*dy);
return dist;
}
@Override
public boolean equals(Object obj) {
boolean retFlag = false;
//Check if the parameter object is of the same class
if( obj instanceof Point) {
Point p = (Point) obj;
//Check if the co-ordinates are same
if(p.x == this.x && p.y == this.y) {
retFlag = true;
}
}
return retFlag;
}
}
public class Point f private int x; private int y; public Point(int x, int y) this.x...
What is wrong with the following code: class Point { private : int x, y; public : Point (int u, int v) : x(u), y(v) {} int getX () { return x; } int getY () { return y; } void setX (int newX ) const { x = newX ; } }; int main () { Point p(5, 3); p.setX (9001) ; cout << p. getX () << ’ ’ << p. getY (); return 0; }
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...
output
What is the output of the following: class Access public int x; private int y public void cal(int x, int y) { this.x = x + 1; this.y = y; } public void print() { System.out.print(""+y); } } class AccessSpecifier { public static void main(String args[]) { Access obj = new Access(); obj.cal(2, 3); System.out.print(obj.x); obj.print(); } } 33 Compilation error 23 None of the available choices Runtime error
QUESTION 1 If we run the following code: A a = new A(1); B b = new B(2); System.out.println(b); Select all of the following pieces of code that would compile and run with no errors, printing the value of 1 followed by the value of 2, each on separate lines. A. public class A { private int y; public A(int y) { this.y = y; } public int getY() { return y; }...
Question 11 (20 points) Given the class Point below, define a class Circle that represent a circle with a given center and radius. The circle class should have a center attribute named center as well as a floating point radius attribute. The center is a point object, defined by the class Point. The class should also have these members: the constructor of the class, which should take parameters to initialize all attributes - a getter for center a setter for...
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...
// ====== 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...
/* FILE: ./shapes7/shape.h */
#include <iostream>
using std::ostream;
class shape{
int x,y;
public:
shape( )
{ x=y=0;}
shape(int xvalue, int yvalue);
void setShape(int new_x, int new_y);
void setX(int new_x);
void setY(int new_y);
int getX( ) const;
int getY( ) const;
virtual void move(int x, int y) = 0;
virtual void shift(int dx, int dy) = 0;
virtual void draw( ) = 0;
virtual void rotate(double r) = 0;
virtual void print(ostream&)const;
friend ostream & operator<<(ostream & os, const shape& s);...
Question 19 Given the following class: public class Swapper ( private int x; private String y public int z; public Swapper( int a, String b, int c) ( x-a; y b; zC; public String swap() ( int temp -x; x-z z temp; return y: public String tostring() ( if (x<z) return y: else return" +x+z What would the following code output? Swapper r new Suapper( 5, "no", 10); System.out.printin( r. swap ) ): no no510 510 e 15 Question 20...
Given the following code fragment public class Point { public int x; // Because these are public, you can access them public int y; // directly without getters and setters }; public class Rectangle { private Point ll; // the lower left corner of the rectangle private Point ur; // the upper right corner of the rectangle public Point getLLPoint() {return ll;} public Point getURPoint() {return ur;} } (a) Write a method equals for the Rectangle class that takes a...