Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2006 Edbt 2006 Workshops Phd Datax Iidb Iiha Icsnw Qlqp Pim Parma And Reactivity On The Web Munich Germany March 2006 Revised Selected Papers Lncs 4254

Authors: Torsten Grust ,Hagen Hopfner ,Arantza Illarramendi ,Stefan Jablonski ,Marco Mesiti ,Sascha Muller ,Paula-Lavinia Patranjan ,Kai-Uwe Sattler ,Myra Spiliopoulou ,Jef Wijsen

2006th Edition

3540467882, 978-3540467885

More Books

Students explore these related Databases questions