Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

image text in transcribed

image text in transcribed

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; 11 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; 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 makePointsFromString(String s) { List result - new ArrayList(); if (s -- null || !s.contains(")")) { return result; } ss.replaceAll("\\s+", "").replaceAll("\", "").replaceAll("W", "W"); 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(Object o) { if (!(o instanceof Point)) { return false; } Point other. (Point) o; return Math.abs(x - other.x) 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: # Question 3 # Uncomment the following lines after completing the question to test your Point class # print ("24:") # points = Point.make_points_from_string ("(1,1.25), (2,5),(-3, 3)") # for p in points: # print (p) # print (f"The distance between {(pl := points[0])} and { (p2 := points[1])} is {pl.distance_to (p2):.2f}.")

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Should flotation costs be included in the estimate?

Answered: 1 week ago

Question

=+2 Is the decision sustainable in the long run?

Answered: 1 week ago