Read the following code and then implement the following parts:
Read the following code and then implement the following parts:
class Point {
public int xCoordinate;
public int yCoordinate;
}
1. Derive a class from Point and call it DerivedPoint, the new class will contain two constructors, the first one takes no arguments, it assigns the point to the point (1,1) and the second constructor takes two parameters that represents the x and y coordinates respectively.
2. The class Point Implements a method called Display that prints a representation of a point in the following format ( x,y ) if invoked on an object of type point.
3. The class DerivedPoint will contain a method called Distance that calculates the Euclidian distance between this DerivedPoint and another DerivedPoint which is provided as a parameter to this method, this method should return the calculated distance.(Hint: use the built in Math class).
4. Implement another class called Triangle, a triangle is specified by three vertices each of which is a DerivedPoint. This class will contain a constructor that takes three parameters of type DerivedPoint. It also will contain a method called IsRight, this method returns true if the triangle invoked by is a Right triangle and false otherwise.
-
Interview Candidate
- Oct 16th, 2015
- 12
- 7226
Showing Answers 1 - 12 of 12 Answers
Related Answered Questions
Related Open Questions
Read the following code and then implement the following parts:
class Point {
public int xCoordinate;
public int yCoordinate;
}
1. Derive a class from Point and call it DerivedPoint, the new class will contain two constructors, the first one takes no arguments, it assigns the point to the point (1,1) and the second constructor takes two parameters that represents the x and y coordinates respectively.
2. The class Point Implements a method called Display that prints a representation of a point in the following format ( x,y ) if invoked on an object of type point.
3. The class DerivedPoint will contain a method called Distance that calculates the Euclidian distance between this DerivedPoint and another DerivedPoint which is provided as a parameter to this method, this method should return the calculated distance.(Hint: use the built in Math class).
4. Implement another class called Triangle, a triangle is specified by three vertices each of which is a DerivedPoint. This class will contain a constructor that takes three parameters of type DerivedPoint. It also will contain a method called IsRight, this method returns true if the triangle invoked by is a Right triangle and false otherwise.
Related Answered Questions
Related Open Questions