Question: Question 2 : Write the below program in Java. Design a class named Point that meets the following requirements: Two data fields w and z

Question 2 : Write the below program in Java.

Design a class named Point that meets the following requirements:

Two data fields w and z for representing a point with getter methods.

A no-arg constructor that constructs a point for (0, 0).

A constructor that constructs a point with the specified w and z values.

Override the equals method. Point p1 is said to be greater than point p2 if p1.w = = p2.w and p1.z = = p2.z.

Implement the Comparable interface and the compareTo method. Point p1 is said to be greater than point p2 if p1.w > p2.w or if p1.w = = p2.w and p1.z > p2.z.

Override the toString() method to return a string as [w value, z value].

Implement the Cloneable interface and clone method.

Complete and run your program using the following code:

public class Ques_02 {

public static void main(String[] args) {

Point1 p1 = new Point1(3, 4);

Point1 p2 = new Point1(3.4, 1.4);

System.out.println(p1.equals(p2));

System.out.println(p1.equals(p1));

System.out.println(p1.compareTo(p2));

System.out.println(p2.compareTo(p1));

Point1 p3 = (Point1)(p1.clone());

System.out.println(p3.equals(p1));

System.out.println(p3); }

}

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!