Question: Design a class named MyPoint to represent a point with x and y-coordinates. The class contains: .Data fields: o Private two double data fields x
Design a class named MyPoint to represent a point with x and y-coordinates. The class contains: .Data fields: o Private two double data fields x and y that represent the coordinates. o Private String date field name that represents the name of the point (e.g. P1). o Static int data field numberOfCreatedPoints that counts how many points are created from the MyPoint class. Methods o A no-arg constructor that creates a point (0, 0) and its name is center o A constructor that initializes a point with specified coordinates. The constructor method should have the following header public MyPoint double xCoor, double yCoor, String pointName) o Three get methods for data fields x, y, and name, respectively o A static method named get o A method named showDetails0 that prints the attributes of a point: its o A method named distance() that returns the distance between any two points that retuns number of created points. coordinates x,and y and its name of the MyPoint type. Use this formula to compute for the distance between two points: distance-(x2-x)2-y1) Write a test program that creates two points (0, 0) and (10, 30.5, P1) and displays number of created points. The program should print the coordinates and name of each point and then displays the distance between them. Here is a sample run Number of created points is 2 First Point Details: Name: center Second Point Details y-30.5 Name: P1 The distance between the center and P1 32.098
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
