Question: Point.java public class Point { public Point(int initialX, int initialY) { x = initialX; y = initialY; } public double distanceFromOrigin() { return Math.sqrt(x *

 Point.java public class Point { public Point(int initialX, int initialY) {

x = initialX; y = initialY; } public double distanceFromOrigin() { return

Point.java

public class Point {

public Point(int initialX, int initialY) {

x = initialX;

y = initialY;

}

public double distanceFromOrigin() {

return Math.sqrt(x * x + y * y);

}

public void setLocation(int newX, int newY) {

x = newX;

y = newY;

}

public void translate(int dx, int dy) {

x = x + dx;

y = y + dy;

}

}

=========

he give us just one file Point Class .

PROGRAM#2: Package Point PointDemo - X: int - Y: int main(String[ args): static void + Point(int initialx, int initialY) + distance From Origin(): double + setLocation(int newx, int newY):void + translate(int dx, int dy): void 1. Write the implementation for above UML 2. Create default constructor and parameterized constructor for point class. 3. Add a new instance variable "attribute to the point class call it color of type int and with a private access modifier. 4. Add setter and getter for the color attribute. 5. Update the parameterized constructor in the Point class to receive a new parameter for color attribute. Call the parameter color. You need to use this pointer to set the color this.color = color 6. Fix the code in the Point Demo class. Now you will have a compilation error because of the new constructor's parameter. 7. Add the following code inside the main function of PointDemo class Point p3 = new Point(); System.out.println("p3: (" + p3.getX() + ", " +p3.getY() + ")" + "Color:" + p3.getColor()); 8. The previous code will cause a compilation error. Why? To fix the error you need to create a default Constructor as the Java doesn't provide default constructor if you defined a parameterized constructor. 9. Create a default constructor in the point class that initializes the attributes to default values x =10, y = 10 and color = 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!