nt: esents a coordinate point on the playing field grid." LON init_(self, x: float, y: float): Construct a point with the given coordinates." istance to (self, other: Point) -> float: Return the distance between this point and the other point."

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
icon
Concept explainers
Question
# #:
# # Part 3
Translation from Java
# ###### #
# #####
# ##
class Point:
"Represents a coordinate point on the playing field grid."
EPSILON =
def
init
(self, x: float, y: float):
"Construct a point with the given coordinates."
def distance to (self, other: Point) -> float:
"Return the distance between this point and the other point."
@staticmethod
def make_points_from_string (s: str) -> list[Point]:
"Make points from a string in a comma-separated format, eg '(1,1), (2.5, 3)'."
def
eq_ (self, o: object) -> bool:
def
repr
(self) -> str:
Transcribed Image Text:# #: # # Part 3 Translation from Java # ###### # # ##### # ## class Point: "Represents a coordinate point on the playing field grid." EPSILON = def init (self, x: float, y: float): "Construct a point with the given coordinates." def distance to (self, other: Point) -> float: "Return the distance between this point and the other point." @staticmethod def make_points_from_string (s: str) -> list[Point]: "Make points from a string in a comma-separated format, eg '(1,1), (2.5, 3)'." def eq_ (self, o: object) -> bool: def repr (self) -> str:
In this part, translate the Java code below into code that does the same thing in Python by completing
the methods in Part 3 of the template. Test your code by uncommenting the last (ungraded) part of the
given assignment template.
/** Represents a coordinate point on the playing field grid. */
public class Point {
public double x; il x coordinate in tile lengths
public double y; // y coordinate in tile lengths
private static final double EPSILON - 0.003; // threshold for coords to be considered equal
/** Constructs a Point. The arguments are in tile lengths. */
public Point (double x, double y) {
this.x - x;
this.y - y;
/** Returns the distance between the two points in tile lengths (feet). */
public double distanceTo(Point other) {
double dx - other.x - x;
double dy - other.y - y;
return Math.sqrt(dx * dx + dy * dy);
/** Makes points from a string in a comma-separated format, eg "(1,1), (2.5,3)". */
public static List<Point> makePointsFromString(String s) {
List<Point> result - new ArrayList<Point>();
if (s -- null || Is.contains(")")) {
return result;
}
s- s. replaceAll("\\s+", "").replaceAll("\\(", "").replaceAll("\\),", ")");
for (String fragment: s.split("\)")) {
String[] xy - fragment.split(", ");
result.add(new Point(Double.parseDouble(xy[@]), Double.parseDouble(xy[1])));
return result;
@Override public boolean equals(0bject o) {
if (!(o instanceof Point)) {
return false;
}
Point other - (Point) o;
return Math.abs (x - other.x) < EPSILON && Math. abs (y - other.y) < EPSILON;
}
@Override publice String tostring(0 {
DecimalFormat fmt - new DecimalFormat ("#.##");
return "(" + fmt.format (x) + ", " + fmt.format(y) + ")";
Transcribed Image Text:In this part, translate the Java code below into code that does the same thing in Python by completing the methods in Part 3 of the template. Test your code by uncommenting the last (ungraded) part of the given assignment template. /** Represents a coordinate point on the playing field grid. */ public class Point { public double x; il x coordinate in tile lengths public double y; // y coordinate in tile lengths private static final double EPSILON - 0.003; // threshold for coords to be considered equal /** Constructs a Point. The arguments are in tile lengths. */ public Point (double x, double y) { this.x - x; this.y - y; /** Returns the distance between the two points in tile lengths (feet). */ public double distanceTo(Point other) { double dx - other.x - x; double dy - other.y - y; return Math.sqrt(dx * dx + dy * dy); /** Makes points from a string in a comma-separated format, eg "(1,1), (2.5,3)". */ public static List<Point> makePointsFromString(String s) { List<Point> result - new ArrayList<Point>(); if (s -- null || Is.contains(")")) { return result; } s- s. replaceAll("\\s+", "").replaceAll("\\(", "").replaceAll("\\),", ")"); for (String fragment: s.split("\)")) { String[] xy - fragment.split(", "); result.add(new Point(Double.parseDouble(xy[@]), Double.parseDouble(xy[1]))); return result; @Override public boolean equals(0bject o) { if (!(o instanceof Point)) { return false; } Point other - (Point) o; return Math.abs (x - other.x) < EPSILON && Math. abs (y - other.y) < EPSILON; } @Override publice String tostring(0 { DecimalFormat fmt - new DecimalFormat ("#.##"); return "(" + fmt.format (x) + ", " + fmt.format(y) + ")";
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Control Structure
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education